From 33714a4dfd8d4c47178f7f07a3850056be7c4058 Mon Sep 17 00:00:00 2001 From: Navid EMAD Date: Wed, 29 Apr 2026 00:36:13 +0200 Subject: [PATCH] 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. --- src/cdp/domains/dom.zig | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cdp/domains/dom.zig b/src/cdp/domains/dom.zig index 33283b2d..843cc20e 100644 --- a/src/cdp/domains/dom.zig +++ b/src/cdp/domains/dom.zig @@ -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