Repository navigation
Conversation
…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.
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.
Fixes #366
Problem
Parsing
[class=XXX'@{foo}-']silently dropped theXXXbetween 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 ofXXX. 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:
Unexpected string found; an attribute value was already defined.~after an operator (not followed by=) now throwsUnexpected "~" 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/oxfmtcould not be run locally (sandbox blocksnpm install); the change follows the surrounding style (tabs, existing error-message wording).