cdp: tighten isXPathQuery '::' heuristic

A bare indexOf("::") matched CSS pseudo-elements (a::before) and
attribute values containing '::' ([data-x="x::y"]), misrouting them
to the XPath evaluator. Require an axis-name shape ([a-zA-Z-])
immediately before '::' so only real axis specifiers like
descendant::p are dispatched to XPath.
This commit is contained in:
Navid EMAD
2026-04-29 00:36:13 +02:00
parent 0fcd47e1e1
commit 33714a4dfd

View File

@@ -104,7 +104,16 @@ fn isXPathQuery(q: []const u8) bool {
if (q[1] == '/') return true;
if (q[1] == '.' and q.len > 2 and q[2] == '/') return true;
}
return std.mem.indexOf(u8, q, "::") != null;
// Require axis-name shape immediately before `::` so CSS pseudo-elements
// (`a::before`) and attribute values containing `::` (`[data-x="x::y"]`)
// aren't misrouted to the XPath evaluator.
var idx: usize = 0;
while (std.mem.indexOfPos(u8, q, idx, "::")) |hit| : (idx = hit + 1) {
if (hit == 0) continue;
const c = q[hit - 1];
if ((c >= 'a' and c <= 'z') or (c >= 'A' and c <= 'Z') or c == '-') return true;
}
return false;
}
// https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-performSearch