Address upstream review comments

This commit is contained in:
jpirnay
2026-04-13 11:15:20 +02:00
parent ee2d608a49
commit 5c567b0a72
4 changed files with 32 additions and 14 deletions
+10 -1
View File
@@ -77,11 +77,20 @@ bool ChapterXPathIndexer::tryExtractParagraphIndexFromXPath(const std::string& x
}
const std::string pKey = "/p[";
const size_t pos = normalized.find(pKey, secondBody != std::string::npos ? secondBody : 0);
const size_t searchStart = secondBody != std::string::npos ? secondBody : 0;
const size_t pos = normalized.find(pKey, searchStart);
if (pos == std::string::npos) {
return false;
}
// Only accept p[...] that is a direct child of the /body segment — reject
// paths with intermediate ancestor segments (e.g. /body/.../div[4]/p[1])
// which would collapse structurally different locations to the same index.
const size_t bodyEnd = (secondBody != std::string::npos ? secondBody : 0) + bodyKey.size();
if (pos != bodyEnd) {
return false;
}
const size_t start = pos + pKey.size();
size_t end = start;
while (end < normalized.size() && std::isdigit(static_cast<unsigned char>(normalized[end]))) {