Browser Interactivity API should escape CSS IDs when building selectors #6211
Labels
feat: browser
Issues and PRs related to the browser runner
p3-minor-bug
An edge case that only affects very specific usage (priority)
pr welcome
Describe the bug
The issue is here:
vitest/packages/browser/src/client/tester/context.ts
Line 47 in a48be6f
You can reproduce this issue just by defining a
<button id=":foo">
and trying to useuserEvent.click()
on it.Almost any string can be a valid HTML ID (see here), but that does not mean it can be used unescaped in a CSS selector. It is possible to escape characters outside the regular range by following these instructions. One could write a small function, e.g.,
sanitizeHtmlIdForCss(htmlId: string): string
, and just call that onel.id
before passing it into the string interpolation in the line of code I linked to above.If this seems worth addressing I can submit this PR myself, just let me know. Thanks!
Reproduction
This is hard/impossible to reproduce in Stackblitz because it only applies in the browser, and I don't think Stackblitz can run those. But if you have a local project that runs tests in the browser, try creating an element with an ID of
:foo
, and call anyuserEvent
method on it.System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: