Skip to content

CSS: a stray closing token no longer drops the level below zero - #136

Merged
tdewolff merged 1 commit into
tdewolff:masterfrom
mokevnin:css-stray-closing-token
Nov 12, 2026
Merged

tdewolff merged 1 commit into
tdewolff:masterfrom
mokevnin:css-stray-closing-token

Conversation

@mokevnin

Copy link
Copy Markdown
Contributor

A closing token without its opening one (a stray ), ] or }) took the parser's nesting level below zero in two places, and nothing after it closed again:

  • parseDeclarationError: the offending ) of an "unexpected ending in declaration" error is popped again in the recovery loop and decremented the level to -1, so the ; that should end the bad declaration no longer did.
    • color:red);display:none (inline) lost display:none.
    • .foo { color:red); display:none } .bar { color:red; } lost the rest of the stylesheet, since the } at level -1 did not end the rule either.
  • parseAtRuleUnknown: @foo { a) } .bar { color:red; } kept the } and .bar { color:red; } as tokens of the unknown at-rule.

Per CSS Syntax, a stray closing token is an ordinary token: the bad declaration ends at the next ; and the block at its }. The fix lowers the level only when one is open. The other decrements already guard against this (p.level == 0 is handled before them).

Tests: four cases in TestParse, failing before the change; go test ./... passes.

🤖 Generated with Claude Code

parseDeclarationError and parseAtRuleUnknown decremented the nesting level on every ')', ']' or '}',
also on one without its opening token. The level went below zero, so the ';' or '}' that should
end the bad declaration or the at-rule no longer did, and everything after it was swallowed:
"color:red);display:none" lost display:none, and ".foo{color:red);display:none}.bar{color:red}"
lost the rest of the stylesheet. A closing token now lowers the level only when one is open.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tdewolff
tdewolff merged commit 78b7cd2 into tdewolff:master Nov 12, 2026
@tdewolff

Copy link
Copy Markdown
Owner

Well spotted, thanks for the fix!

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