Skip to content

Anchor the alternation in the :link and :placeholder-shown tests - #181

Open
jdalton wants to merge 1 commit into
dperini:masterfrom
jdalton:fix/link-precedence
Open

Anchor the alternation in the :link and :placeholder-shown tests#181
jdalton wants to merge 1 commit into
dperini:masterfrom
jdalton:fix/link-precedence

Conversation

@jdalton

@jdalton jdalton commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

/^a|area$/ alternates ^a with area$ rather than anchoring an alternation, so :link and :any-link match any element whose name begins with a, <abbr href> among them. /^input|textarea$/ in :placeholder-shown has the same shape.

Detail, and how it was checked

/^a|area$/ reads as ^a or area$, so it accepts any element whose name begins with a. :link and :any-link therefore match <abbr href="...">, where browsers match only <a> and <area>. It agrees with browsers on those two, which is why the test suites do not catch it.

/^input|textarea$/ in :placeholder-shown has the same shape; there the surrounding conditions happen to mask it.

The link test is hoisted into a helper at the same time, so the three places that need it share one definition.

Extracted from #167 as a standalone change: one file, applies to master on its own, and checked against a fixture to confirm it fixes what it describes and moves nothing else.

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

This patch applies to master on its own. The sixteen in this series were checked by cherry-picking them onto master one after another, in this order and in reverse, and all sixteen land without a conflict.

@jdalton
jdalton force-pushed the fix/link-precedence branch from bbdec0e to 52dfea1 Compare September 4, 2026 18:00
/^a|area$/ alternates '^a' with 'area$' rather than anchoring an alternation, so it accepts any element whose name begins with 'a'. ':link' and ':any-link' therefore match <abbr href="...">, where browsers match only <a> and <area>. It agrees with browsers on those two, which is why the test suites do not catch it.
 /^input|textarea$/ in ':placeholder-shown' has the same shape; there the surrounding conditions happen to mask it.
 The link test is hoisted into a helper at the same time, so the three places that need it share one definition.

References:

- Spec: https://drafts.csswg.org/selectors-4/#the-any-link-pseudo — ':any-link' matches an a or area element with an href
- Spec: https://html.spec.whatwg.org/#selector-placeholder-shown — ':placeholder-shown', for the pattern of the same shape
- Chromium: https://github.com/chromium/chromium/blob/155.0.8041.1/third_party/blink/renderer/core/css/selector_checker.cc#L2550 — ':any-link' is one IsLink() predicate
- Chromium: https://github.com/chromium/chromium/blob/155.0.8041.1/third_party/blink/renderer/core/css/selector_checker.cc#L2553 — ':link' is the same predicate, unvisited
- MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/:any-link
@jdalton

jdalton commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author

This one sits with #179 and #180, which touch the parser and pattern fixes.

They do not depend on each other. All seventeen in the series cherry-pick onto master in any order, and I checked that in both directions, so any one of these can land alone. The order below is the one they read best in:

  • #179 fixes the forgiving fallback and the EOF-terminated argument.
  • #180 lets a pseudo-class be followed by a quoted attribute selector.
  • #181 anchors the alternation in the :link and :placeholder-shown tests.

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