Skip to content

fix: reject content dropped between an attribute operator and a quoted value - #368

Merged
MoOx merged 3 commits into
postcss:mainfrom
Ultroncn:fix/attribute-junk-before-quoted-value
Nov 26, 2026
Merged

MoOx merged 3 commits into
postcss:mainfrom
Ultroncn:fix/attribute-junk-before-quoted-value

Conversation

@Ultroncn

Copy link
Copy Markdown
Contributor

Fixes #366

Problem

Parsing [class=XXX'@{foo}-'] silently dropped the XXX between the operator and the quoted value: the bare word was first read as the value, then the string token overwrote it, so the resulting AST carried no trace of XXX. The same silent drop happened for a bare ~ in [class=~'@{foo}-'] — the LESS escape syntax this issue was filed against, which is not valid in LESS 5 either.

Fix

Reject both cases with a parse error instead of silently discarding input:

  • A string token arriving after a value is already defined now throws Unexpected string found; an attribute value was already defined.
  • A bare ~ after an operator (not followed by =) now throws Unexpected "~" found; an operator was already defined.

Valid selectors are unaffected: quoted values, unquoted values, ~= and the other operators, and Sass interpolations ([lang=#{$locale}], [#{$attr}=#{$value}]) all still parse as before.

Tests

Added regression tests for both reported inputs in src/__tests__/exceptions.mjs. The new tests fail on the old code (verified by stashing the fix) and pass with it. Full suite: 1078 passing (node --test src/__tests__/*.mjs); typecheck clean.

Note: oxlint/oxfmt could not be run locally (sandbox blocks npm install); the change follows the surrounding style (tabs, existing error-message wording).

Ultroncn and others added 3 commits November 18, 2026 13:20
…d value

Fixes postcss#366

Parsing `[class=XXX'@{foo}-']` silently dropped the `XXX` between the
operator and the quoted value: the bare word was first read as the
value, then the string overwrote it. The same silent drop happened for
a bare `~` in `[class=~'@{foo}-']`, the LESS escape syntax the issue
was filed against (not valid in LESS 5).

Reject both cases with a parse error instead of silently discarding
input: a string token after a value is already defined now errors, and
a bare `~` after an operator (not followed by `=`) now errors. Valid
selectors are unaffected: quoted values, unquoted values, `~=` and
other operators, and Sass interpolations all still parse.

Added regression tests to src/__tests__/exceptions.mjs. Full suite:
1078 passing (node --test src/__tests__/*.mjs); typecheck clean.
@MoOx
MoOx merged commit 37f6775 into postcss:main Nov 26, 2026
4 checks passed
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.

Misparsed attribute selector

2 participants