Repository navigation
Quote link text safely in XPath and run xcrun without a shell - #2678
Merged
Merged
Conversation
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>
Member
|
Thank you @ofri-peretz ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
click.byLinkText,byPartialLinkText,byText(and theAndWaitvariants), the matchingmouse.singleClickmethods, and thetext:/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, likeDon't miss, made an invalid XPath expression and the command failed.xcrun simctl io <udid> recordVideo ... <tmpVideo>as a single string and ran it withshell: true. When the result directory has a space in its path, the shell splits the path and recording breaks.The fix
xpathLiteral()inselectorParser.js: it uses single quotes when the text has no apostrophe (so current XPaths are unchanged), double quotes when it has an apostrophe, andconcat()when it has both, since XPath 1.0 has no escape character. All the call sites above use it.execa('xcrun', [...args])with an argument array and no shell.How I verified it
test/unittests/selectorParserTest.js(four cases: plain text, apostrophe, both quote kinds, and thelink:locator). It passes withnpx ava test/unittests/selectorParserTest.js.eslintpasses on the changed files.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.