fix(selectors): emit valid XPath 1.0 string literals via concat()

Both the Go translator and the V8 runtime escaped " by prepending \,
which XPath 1.0 doesn't accept (its string literals have no escape
syntax). A `text:` value containing a quote produced malformed XPath
that chromedp/document.evaluate rejected.

Use the standard concat() composition: when the value contains both
' and ", split on " and join with `, '"', ` so each fragment is
wrapped in single or double quotes individually.
This commit is contained in:
pj committed 2026-05-03 11:00:23 +07:00
1 parent a69bac7abd
commit 372fd23d87
3 files changed
+40 -5

No files matched your search

+3
View File
@@ -13,6 +13,9 @@ func TestTranslateStringSelector_KnownKeys(t *testing.T) {
{"class:btn-primary", `[class~="btn-primary"]`, false},
{"tag:button", `button`, false},
{"text:Sign in", `//*[normalize-space(text())="Sign in"]`, true},
{`text:Say "hi"`, `//*[normalize-space(text())='Say "hi"']`, true},
{`text:it's`, `//*[normalize-space(text())="it's"]`, true},
{`text:it's "fine"`, `//*[normalize-space(text())=concat("it's ", '"', "fine", '"', "")]`, true},
{"desc:logout", `[aria-label="logout"]`, false},
{"label:logout", `[aria-label="logout"]`, false},
{"accessibilityLabel:logout", `[aria-label="logout"]`, false},