Skip to content

Quote link text safely in XPath and run xcrun without a shell - #2678

Merged
soulgalore merged 1 commit into
sitespeedio:mainfrom
ofri-peretz:fix-link-text-quotes
Dec 4, 2026
Merged

soulgalore merged 1 commit into
sitespeedio:mainfrom
ofri-peretz:fix-link-text-quotes

Conversation

@ofri-peretz

Copy link
Copy Markdown
Contributor

What was wrong

  • click.byLinkText, byPartialLinkText, byText (and the AndWait variants), the matching mouse.singleClick methods, and the text: / link: selector prefixes put the text straight into an XPath literal wrapped in single quotes, e.g. //a[text()='${text}']. Link text with an apostrophe, like Don't miss, made an invalid XPath expression and the command failed.
  • The iOS Simulator recorder built xcrun simctl io <udid> recordVideo ... <tmpVideo> as a single string and ran it with shell: true. When the result directory has a space in its path, the shell splits the path and recording breaks.

The fix

  • New xpathLiteral() in selectorParser.js: it uses single quotes when the text has no apostrophe (so current XPaths are unchanged), double quotes when it has an apostrophe, and concat() when it has both, since XPath 1.0 has no escape character. All the call sites above use it.
  • The recorder now calls execa('xcrun', [...args]) with an argument array and no shell.

How I verified it

  • Added test/unittests/selectorParserTest.js (four cases: plain text, apostrophe, both quote kinds, and the link: locator). It passes with npx ava test/unittests/selectorParserTest.js.
  • eslint passes on the changed files.
  • I don't have an iOS Simulator setup, so I checked only that the recorder module imports. The arguments are the same ones as before.

The eslint-plugin-secure-coding and eslint-plugin-node-security rules flagged both spots.

AI disclosure: drafted with AI assistance (Claude); I reviewed and tested the change.

click.byLinkText, byPartialLinkText, byText and their AndWait variants,
the mouse.singleClick equivalents, and the text:/link: selector prefixes
put the text into an XPath literal wrapped in single quotes. Text with an
apostrophe ("Don't miss") produced an invalid expression and the command
failed. Add xpathLiteral(), which picks the quote kind that the text does
not contain and falls back to concat() when it contains both.

The iOS Simulator recorder built the xcrun command as one string and ran
it through a shell, so a result directory with a space in its path broke
video recording. Pass the arguments as an array to execa instead.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@soulgalore
soulgalore merged commit 29a16cd into sitespeedio:main Dec 4, 2026
20 checks passed
@soulgalore

Copy link
Copy Markdown
Member

Thank you @ofri-peretz !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants