fix(web): quotes in a string role name no longer break chained locators

Merged
OK
2mo ago
+39-3

Fixes ENG-863 (4 e2e feedback reports on 0.16.0).

  • getByRole('button', { name: "Yes, I'm sure" }) threw InvalidSelectorError once chained (.first(), nth, filter, or the engine's own >> e2e-read). Regression from #669: glyphTolerantName turns a string name into a u-flag RegExp for \p{Co}, and Playwright 1.63 escapeRegexForSelector skips escaping u/v regexes, 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/\x60 and >> to >\x3e in u/v regexes. 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 (getByRole name, getByText, getByLabel, getByPlaceholder, hasText, getByTestId), which had the same gap with a /.../u pattern.
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> then expect(screen.getByRole('button', { name: "Yes, I'm sure" }).first()).toBeVisible() + .tap()
  • tests/integration/icon-glyph-names.test.ts new case (exact/substring name, visible, u and v text, u testId, all chained) fails on main with the same error, passes here
  • testbed suite 70/70, web benchmark 90/90
mainthis branch
× role name with an apostrophe
ENGINE_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 567ms
Tests 1 passed (1)