diff --git a/lib/KOReaderSync/ChapterXPathIndexer.cpp b/lib/KOReaderSync/ChapterXPathIndexer.cpp index d8b122fc..39783e31 100644 --- a/lib/KOReaderSync/ChapterXPathIndexer.cpp +++ b/lib/KOReaderSync/ChapterXPathIndexer.cpp @@ -95,7 +95,17 @@ bool ChapterXPathIndexer::tryExtractParagraphIndexFromXPath(const std::string& x // cannot be mapped to our flat LUT index — the p[4] there is the 4th sibling inside // div[2], not the 4th

child of . Deeply-nested XPaths fall through to // ChapterXPathIndexer::findProgressForXPath which handles full-ancestry matching. - const size_t bodyEnd = (secondBody != std::string::npos ? secondBody : 0) + bodyKey.size(); + size_t bodyEnd = (secondBody != std::string::npos ? secondBody : 0) + bodyKey.size(); + if (bodyEnd < normalized.size() && normalized[bodyEnd] == '[') { + const size_t idxStart = bodyEnd + 1; + size_t idxEnd = idxStart; + while (idxEnd < normalized.size() && std::isdigit(static_cast(normalized[idxEnd]))) { + idxEnd++; + } + if (idxEnd < normalized.size() && normalized[idxEnd] == ']') { + bodyEnd = idxEnd + 1; + } + } if (pos != bodyEnd) { return false; }