Skip to content

fix(rules): attribute operator selectors narrow an a11y style rule's subject #984 - #985

Merged
nc9 merged 1 commit into
mainfrom
fix/984-attr-operators
Oct 21, 2026
Merged

nc9 merged 1 commit into
mainfrom
fix/984-attr-operators

Conversation

@nc9

@nc9 nc9 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

What

An attribute selector with an operator ([a^=v], [a$=v], [a*=v], [a~=v], [a|=v], with i/s flags) now keeps its attribute in the rule's subject. A rule such as .is-open [id$="-drawer"] { display:none !important } reaches only elements that have the attribute with a value that could satisfy it, not every element including <html>. Any other [name…] form (an unread value) still requires its attribute by name. A namespaced or escaped name narrows nothing.

couldMatch now compares attribute values (ASCII case-insensitive, a superset of a browser's match) for = and each operator, so .is-open [id="drawer"] no longer makes an <input id="q"> unconfirmed. Operator selectors stay undecidable: an element that can satisfy one stays unconfirmed, never hidden or shown. Two edge cases from the codex pass are covered: HTML attributes aK and ak are distinct (either may satisfy the test), and a literal NUL in a value (U+FFFD in a browser) is not ruled out.

Tests

New page-styles-attr-operators-984.test.ts (parser cases, the issue's repro table through aria-command-name and form-labels, matching and non-matching values per operator, edge shapes) and 15 Chromium-rendered rows in static-hidden-chromium.json. 24 of the new tests fail against the old source. Docs: solution text of the a11y naming rules and the button-name and aria-hidden-focus pages mention operator selectors; tangly check --strict passes.

Closes #984

skills: no change

@claude

claude Bot commented Oct 21, 2026

Copy link
Copy Markdown

Reviewed the diff, mainly packages/rules/src/shared/page-styles.ts. I didn't run the tests or check CI.

I found no correctness or security problems. The narrowing in couldMatch stays a superset of what a browser matches, so it can only turn "unconfirmed" into a decision where the old code was already over-conservative. The cases I traced:

  • Values are compared ASCII case-insensitively.

  • An empty value never matches for ^=, $=, *= and ~=.

  • A ~= value containing whitespace never matches.

  • Escaped or unquoted-with-escape values, and namespaced names, fall back to presence-only or nothing.

  • NUL and U+FFFD are treated as possible matches.

  • aK and ak are both tried.

  • (low) page-styles.ts couldMatch: it now runs Array.from(view.el.attributes) for every attribute test on every element for every uncertain rule. On a large DOM with many uncertain rules that allocates a lot. Reading the attributes once per ElementView, or only when the attribute test has an operator, would avoid it.

  • (nit) readOperatorAttr: the i/s flag directly after an unquoted identifier value ([a=b i]) relies on the whitespace before the flag. A test for [a=bi] (no flag) would pin that down. If it already exists in the new test file, ignore this.

  • (nit) The long solution strings are duplicated across 7 rules. A shared constant would keep them from drifting, though that matches the existing style.

Test coverage is good: parser cases, per-operator match and non-match, and Chromium-rendered fixtures.

@nc9
nc9 merged commit b3e71a7 into main Oct 21, 2026
15 checks passed
@nc9
nc9 deleted the fix/984-attr-operators branch October 21, 2026 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

a11y style reader: an attribute selector with an operator ([a$=v], [a^=v], [a*=v]) matches every element, so one rule leaves the whole page unconfirmed

1 participant