Stop :autofill matching every element - #196
Open
jdalton wants to merge 1 commit into
Open
Conversation
':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
This was referenced Sep 5, 2026
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.
:autofilland:-webkit-autofillare handled by thepseudo_nopgroup, which breaks out of the compile loop without emitting a test. A resolver with no test accepts whatever it is given, so:autofillmatches every element in the document andinput:autofillmatches every input.Detail, and how it was checked
The group is claimed and then abandoned:
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>:2e9498f:autofillhtml, head, body, a, binput:autofillapbbbEmitting 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 rawe.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.
:autofillmatches a control the user agent has autofilled.selector_checker.cc#L2778— the state is read from the control, not inferred.:autofill.Found while reviewing #178, where the unguarded
e.matches()in the unreachable handler turned up.