Skip to content

🐛 fix(css): keep stray brackets stable on repeat - #2194

Merged
gaborbernat merged 5 commits into
tox-dev:mainfrom
gaborbernat:sec-fix/issue-1853
Nov 15, 2026
Merged

gaborbernat merged 5 commits into
tox-dev:mainfrom
gaborbernat:sec-fix/issue-1853

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

minify_css and minify_css_inline could give a different result when run a second time on some input with stray brackets, hex escapes or CDO/CDC tokens. Running the minifier on its own output could therefore change the stylesheet, which breaks pipelines that minify more than once. 🧱 Once this merges, a second pass returns the first pass's output unchanged. Fixes #1853.

Each mismatch came from the first pass writing text that a second pass reads differently. The first pass now writes what the second pass would read: a declaration whose name opened a block is dropped, an ident stays apart from a following (, a group left open at the end of the input is closed, and an escaped name keeps the closing space the second pass expects. The rules follow CSS Syntax 3, which defines how such input is parsed.

Behavior changes

  • A declaration whose name holds a block opened before its colon is dropped, in a stylesheet and in a style attribute.
  • A stray ident followed by ( in stylesheet text is separated from it by a space.
  • A nested calc() or group left open at the end of the input folds to its value.
  • A raw at-keyword ending in a hex escape before a prelude gets two spaces before the prelude, as a spelled name already does.
  • A stray CDO or CDC followed by an at-statement, with no delimiter between, gets a ; before the at-statement.

A stray bracket, or an ident written apart from a `(`, came out of the
first minify pass in a form that the second pass changed. A declaration
whose name opened a block before its colon was kept on the first pass
and dropped on the second. An ident followed by `(` joined into a
function token, which the second pass closed. A nested calc() left open
at the end of the input stayed unfolded until the second pass.

A name that opens a block is no declaration, so the first pass drops
it. An ident written apart from a `(` gets a space in stray text, and a
block left open after a hex escape gets the space the second pass
writes. A nested calc() or group that reaches the end of the input is
folded on the first pass.

Fixes tox-dev#1853
@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-1853 (6da3b85) with main (3f6b2d4)

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. ↩

A raw at-keyword name that ends in a hex escape took no closing space,
so the first pass wrote one space before the prelude and the second
pass, reading the escape's space back as part of the name, wrote two.

A stray `}` or `;` after stray text that was written after the last
delimiter cleared the delimiter owed before the next at-statement, so
the first pass joined the two and the second pass split them again.

Write the closing space for a raw name that ends in a hex escape, as a
spelled name does, and keep the delimiter before an at-statement that
follows stray text.

Fixes tox-dev#1853
# Conflicts:
#	src/turbohtml/_c/css/minify/css_calc.h
@gaborbernat
gaborbernat merged commit ec33035 into tox-dev:main Nov 15, 2026
30 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_inline output for stray brackets changes on a second pass

1 participant