Skip to content

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

Merged
dperini merged 1 commit into
dperini:masterfrom
jdalton:fix/link-precedence
Sep 5, 2026
Merged

dperini merged 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.

@dperini
dperini merged commit ec4bcf3 into dperini:master Sep 5, 2026
jdalton added a commit that referenced this pull request Sep 17, 2026
Consolidated commits:
- a959b4a Fix the forgiving fallback and EOF-terminated arguments
  Original author: John-David Dalton <john.david.dalton@gmail.com>
- 8a91824 Anchor the alternation in the :link and :placeholder-shown tests
  Original author: John-David Dalton <john.david.dalton@gmail.com>
- efa85cb Answer an id selector from the id map instead of walking
  Original author: John-David Dalton <john.david.dalton@gmail.com>
- 538f744 Merge pull request #179 from jdalton/fix/forgiving-and-eof
  Original author: Diego Perini <diego.perini@gmail.com>
- c545320 Establish shared legacy runtime initialization
  Original author: jdalton <john.david.dalton@gmail.com>
- 5d68c9b Merge pull request #197 from jdalton/refactor/legacy-runtime-init
  Original author: John-David Dalton <jdalton@users.noreply.github.com>
- ec4bcf3 Merge pull request #181 from jdalton/fix/link-precedence
  Original author: Diego Perini <diego.perini@gmail.com>
- fe15bc3 Merge pull request #183 from jdalton/perf/id-lookup
  Original author: John-David Dalton <jdalton@users.noreply.github.com>
- d7e01ee Add a jsdom selector-engine adapter
  Original author: jdalton <john.david.dalton@gmail.com>
- 62d45eb Merge pull request #211 from jdalton/feat/jsdom-adapter
  Original author: John-David Dalton <jdalton@users.noreply.github.com>
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.

2 participants