Skip to content

🐛 fix(css): keep rules led by a combinator - #2192

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:sec-fix/issue-1850
Nov 15, 2026
Merged

gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:sec-fix/issue-1850

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

The CSS minifier could drop or merge a rule whose selector starts with a combinator (>, +, ~ or ,) when the rule before it ended with a custom property. The rule could lose its combinator, turn into an at-rule, vanish, or merge into the rule before it, which changes the elements it styles. 🧭 Once this merges, such a rule keeps its combinator and stays a separate rule. Fixes #1850.

The selector minifier trims trailing spaces only within the selector it is writing, so it can no longer reach into the text of earlier rules in the shared buffer. The empty-prelude guard that covered the same overrun is removed.

Behavior changes

A rule whose selector starts with >, +, ~ or , keeps its combinator in the cases above. Other input is unchanged.

A selector that starts with a combinator has no compound before the
combinator, so the trailing-space trim after it could run past the
selector's start. The selector is rendered into the shared pool after
the body, and a custom property value at the end of the body can leave
a space there. The trim removed bytes of earlier output and the
combinator was written over them, so the rule could lose the combinator,
turn into an at-rule, disappear, or merge into the rule before it.

Every trim in the selector minifier now stops at the selector's start.
The empty-prelude guard in css_parse_qualified existed only to undo the
same overrun, so it is gone.

Fixes tox-dev#1850
@gaborbernat gaborbernat added the bug Something isn't working label Nov 15, 2026
@codspeed

codspeed Bot commented Nov 15, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 582 untouched benchmarks
⏩ 89 skipped benchmarks1


Comparing gaborbernat:sec-fix/issue-1850 (26313cf) with main (8c70f88)

Open in CodSpeed

Footnotes

  1. 89 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@gaborbernat
gaborbernat merged commit efd4b6a into tox-dev:main Nov 15, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

minify_css trims a leading combinator into the previous rule

1 participant