Repository navigation
fix(aria): read role tokens and aria state values case-insensitively - #43680
Closed
JohnnyXu (xubenqiang) wants to merge 1 commit into
Closed
JohnnyXu (xubenqiang) wants to merge 1 commit into
JohnnyXu (xubenqiang) wants to merge 1 commit into
Conversation
ARIA role tokens and the enumerated state values (`aria-checked`, `aria-pressed`, `aria-expanded`, `aria-readonly`, `aria-invalid`) are ASCII case-insensitive, but the injected role engine compared them with exact strings. `role="Button"` was therefore not a button at all, and `aria-checked="True"` / `aria-pressed="True"` read as false, so `getByRole` and the aria snapshot disagreed with what Chromium exposes.
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.
Fixes #43662
ARIA role tokens and the enumerated state values (
aria-checked,aria-pressed,aria-expanded,aria-readonly,aria-invalid) are ASCII case-insensitive, butpackages/injected/src/roleUtils.tscompared them with exact strings. So:role="Button"was not a button at all (it fell through to the implicit role / text),aria-checked="True",aria-pressed="True"andaria-expanded="True"read as false,aria-readonly="True"read as not readonly,aria-invalid="Spelling"fell back totrueinstead ofspelling.getByRole,role=selectors and the aria snapshot therefore disagreed with what Chromium exposes for the same DOM.Change
packages/injected/src/roleUtils.tsgetExplicitAriaRole: lowercase the role tokens before matching.getChecked,getAriaPressed,getAriaExpanded: lowercase the attribute value before comparing (themixed/undefinedcases are unchanged).getReadonly,getAriaInvalid: same normalisation.Test
tests/page/selectors-role.spec.ts—SE-052b should match mixed-case role tokens and aria state values: three elements withrole="checkbox" aria-checked="True",role="Button" aria-pressed="True"androle="button" aria-expanded="True"; assertsrole=checkbox[checked],getByRole('checkbox', { checked: true }),getByRole('button')(2),pressed: true,expanded: true, and the aria snapshot ([checked],[pressed],[expanded],button "bold").Verified red/green on Windows 11 with the bundled chromium:
Expected: 1, Received: 0(the firstrole=checkbox[checked]assertion);tests/page/selectors-role.spec.tsonchromium-page— 22 passed.