Skip to content

Stop :autofill matching every element - #196

Open
jdalton wants to merge 1 commit into
dperini:masterfrom
jdalton:fix/autofill-nop
Open

Stop :autofill matching every element#196
jdalton wants to merge 1 commit into
dperini:masterfrom
jdalton:fix/autofill-nop

Conversation

@jdalton

@jdalton jdalton commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

:autofill and :-webkit-autofill are handled by the pseudo_nop group, which breaks out of the compile loop without emitting a test. A resolver with no test accepts whatever it is given, so :autofill matches every element in the document and input:autofill matches every input.

Detail, and how it was checked

The group is claimed and then abandoned:

else if ((match = selector.match(Patterns.pseudo_nop))) {
  break;
}

Nothing is added to the compiled source, so the resolver answers true for whatever reaches it. On <input id=a><p id=b>x</p>:

selector master 2e9498f with this patch jsdom's engine
:autofill html, head, body, a, b nothing nothing
input:autofill a nothing nothing
p b b b

Emitting a test that never passes keeps the selector valid to write, which is what the group is for, and answers it the way a host with no autofill state should.

The case 'autofill' further down the same switch is unreachable today, because this group claims the selector first. Routing there would be the browser-accurate answer, and it belongs with #178: the call it makes is a raw e.matches(), which is the call that recurses under a host whose matcher routes back into this engine.

References: the spec, the browser source, and what each part was reasoned from

This patch applies to master on its own, and applies cleanly alongside the others in this series in any order.

Found while reviewing #178, where the unguarded e.matches() in the unreachable handler turned up.

':autofill' and ':-webkit-autofill' are handled by the pseudo_nop group, which breaks out of the compile loop without emitting a test. A resolver with no test accepts whatever it is given, so ':autofill' matches every element in the document and 'input:autofill' matches every input.
 Emitting a test that never passes keeps the selector valid, which is what the group is for, and answers it the way a host with no autofill state should: matching nothing. That is also what the reference engine answers.
 The case that reads the host, further down the same switch, is unreachable today because this group claims the selector first. Routing there would be the browser-accurate answer, and it belongs with the re-entrancy fix in dperini#178, since the call it makes is the one that recurses under a host whose matcher routes back into this engine.

References:

- Spec: https://html.spec.whatwg.org/#selector-autofill — ':autofill' matches a control the user agent has autofilled
- Chromium: https://github.com/chromium/chromium/blob/155.0.8041.1/third_party/blink/renderer/core/css/selector_checker.cc#L2778 — the state is read from the control, not inferred
- MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/:autofill
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.

1 participant