Skip to content

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 #984

Closed

Description

@nc9

What happens

In the a11y style reader (packages/rules/src/shared/page-styles.ts), an attribute selector with an operator ([a^=v], [a$=v], [a*=v], [a~=v], [a|=v]) is dropped from the compound it belongs to. parseSelector keeps only plain [attr] / [attr=value] parts (readPlainAttr). Anything else sets complex = true and adds nothing.

So in a rule such as:

.is-open [id$="-drawer"] { display: none !important }

the subject compound is empty, and couldMatch(subject, el) is true for every element, including <html>. The rule is uncertain and may hide, so every element answers display: "unknown". Every unnamed control on the page then becomes <check>-unconfirmed, even when no element on the page has a matching attribute.

The same happens without a combinator: [id$="-drawer"] { display:none } alone is enough.

A related but narrower gap: for the plain [attr=value] parts it does keep, couldMatch() checks only that the attribute is present, never its value. So .is-open [id="drawer"] makes every element that has any id unconfirmed.

Seen in a cloud report

Cloud report 01M5EM63HV1SJM0D0MD23EDQ7J (scheduled audit, engine v0.0.123, which already includes the #978 fix; 10 pages; not a WordPress site) has 37 unconfirmed rows across the six naming rules: button-name, aria-command-name, aria-input-field-name, aria-labels, form-labels and aria-hidden-focus.

A local replay of the stored crawl, with the cascade instrumented to record which rule makes each answer "unknown", traced the 234 control lookups that came back unknown on 9 pages:

Count Cause Status
129 (55%) One rule shaped like .is-x #id, .is-x [id$="…"] { display:none !important }. Its [id$=…] part matches 0 elements on every page, yet makes <html> unknown, so it covers every control on 4 of the 9 pages. this gap
48 A state-class-gated hide of one id (.is-x.y #id { display:none !important }) correct: the ancestor state is runtime
52 Descendants of a display:none custom-element subtree (tree may differ) by design
5 A plain <style> hide on a page that also loads external stylesheets by design

Minimal repro (rules package, v0.0.123)

Page body: <div class="nav"><button type="button"></button></div><form><input type="text" id="q"></form>, run through a11y/aria-command-name and a11y/form-labels.

<style> aria-command-name form-labels
(none) fail fail
.is-open [id="drawer"]{display:none !important} fail -unconfirmed (the input has an id)
.is-open [id$="-drawer"]{display:none !important} -unconfirmed -unconfirmed
.is-open [href^="#modal"]{display:none !important} -unconfirmed -unconfirmed
.is-open [data-state*="closed"]{display:none !important} -unconfirmed -unconfirmed
[id$="-drawer"]{display:none} -unconfirmed -unconfirmed

No element in the repro has an attribute that could satisfy any of these selectors.

Why narrowing is safe

Every attribute operator requires the attribute to be present. So keeping { name } in the subject is always sound, and it alone stops the "every element, including <html>" fan-out.

Comparing the value as well, case-insensitively (a superset of what the browser matches):

  • ^= starts-with;
  • $= ends-with;
  • *= contains;
  • ~= a whitespace-separated word;
  • |= equal to the value, or the value followed by -.

That uses the same static-DOM assumption the reader already makes for .class and #id parts. An empty value ([a^=""], [a$=""], [a*=""]) matches nothing. The i/s flags can be handled, or left to narrow by name only.

Acceptance Criteria

  • parseSelector keeps an operator attribute's name in the subject compound. [id$="-x"], [href^="#"], [data-a*="b"], [class~="a"] and [lang|="en"] each give a subject that requires that attribute, and an element without it is not reached (the repro rows above with no matching element give decided fail, not -unconfirmed).
  • An uncertain rule's attribute parts are compared by value in couldMatch(), case-insensitively, for =, ^=, $=, *=, ~= and |=. An element whose value cannot satisfy them is not reached, so .is-open [id="drawer"] no longer makes an <input id="q"> unconfirmed.
  • An element that does satisfy the attribute part, for example <div id="cart-drawer"> under .is-open [id$="-drawer"]{display:none !important}, stays unknown/-unconfirmed and is never decided "hidden" or "shown".
  • The CHROMIUM invariant table in packages/rules/tests/static-hidden.test.ts gains operator-attribute cases, and no case where Chromium shows the element answers "hidden".
  • Rule docs that describe what the style reader decides (the a11y naming rules' solution text and docs pages) mention attribute selectors with operators; make validate passes in docs/.

Activity

  1. added
    bug
    size: S
    rules
    on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugrulessize: S

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions