fix(web): quotes in a string role name no longer break chained locators
Merged
OK
2mo ago+39+39+01234567890123456789-3-3-0123456789
Fixes ENG-863 (4 e2e feedback reports on 0.16.0).
getByRole('button', { name: "Yes, I'm sure" })threwInvalidSelectorErroronce chained (.first(),nth, filter, or the engine's own>> e2e-read). Regression from #669:glyphTolerantNameturns a string name into au-flag RegExp for\p{Co}, and Playwright 1.63escapeRegexForSelectorskips escapingu/vregexes, so a bare'opens a quote in the selector parser and swallows the rest.- New
selectorSafeRegExp(packages/web/src/locators.ts:24) rewrites quotes to\x22/\x27/\x60and>>to>\x3einu/vregexes. Same matches, nothing for the parser to trip on. Keeps\p{Co}, so supplementary-plane icon glyphs still match. - Applied to the glyph-tolerant role name and every user RegExp (
getByRolename,getByText,getByLabel,getByPlaceholder,hasText,getByTestId), which had the same gap with a/.../upattern.
heading[name=/^[\s\p{Co}]*Don't[\s\p{Co}]+... >> nth=0 >> e2e-read=... # before: parser opens a quote at '
heading[name=/^[\s\p{Co}]*Don\x27t[\s\p{Co}]+... >> nth=0 >> e2e-read=... # after
Verified
Ran it locally: yes
- testbed, built CLI, scratch test injecting
<button>Yes, I'm sure</button>thenexpect(screen.getByRole('button', { name: "Yes, I'm sure" }).first()).toBeVisible()+.tap() tests/integration/icon-glyph-names.test.tsnew case (exact/substring name,visible,uandvtext,utestId, all chained) fails on main with the same error, passes here- testbed suite 70/70, web benchmark 90/90
| main | this branch |
|---|---|
× role name with an apostropheENGINE_FAILURE: locate failed: locator.evaluateAll: InvalidSelectorError: Error while parsing selector button[name=/^[\s\p{Co}]*Yes,[\s\p{Co}]+I'm[\s\p{Co}]+sure[\s\p{Co}]*$/u] >> nth=0 >> e2e-read=... - unexpected symbol ">" at position 74 | ✓ role name with an apostrophe 567msTests 1 passed (1) |