The CSS minifier merges a rule into an earlier one past a rule that sets the same property, so the cascade changes. Both cases keep color:red on b and fold the second a rule into the first, which lets green beat red on an element matching both selectors:
from turbohtml.clean import minify_css
minify_css("a{color:blue}b{c:d\\(;color:red}a{color:green}")
# 'a{color:blue;color:green}b{c:d\\(;color:red}'
minify_css("a{color:blue}b{c:url(x(y);color:red}a{color:green}")
# 'a{color:blue;color:green}b{c:url(x(y);color:red}'
Expected: each input comes back with the three rules in order, since b sets color between the two a rules.
The merge check reads property names back out of each rendered body with a character scan, while the parser splits declarations by token. An escaped \( is part of an ident token, and the ( inside url(x(y) belongs to the URL token, but the scan counts both as an open paren and never sees the ; that ends the declaration, so it misses color. #972 bounds the scan and fixes the [; and stray ) cases; these two need the names taken from the token stream, as tdewolff/parse, css-tree and lightningcss do.
The CSS minifier merges a rule into an earlier one past a rule that sets the same property, so the cascade changes. Both cases keep
color:redonband fold the secondarule into the first, which lets green beat red on an element matching both selectors:Expected: each input comes back with the three rules in order, since
bsetscolorbetween the twoarules.The merge check reads property names back out of each rendered body with a character scan, while the parser splits declarations by token. An escaped
\(is part of an ident token, and the(insideurl(x(y)belongs to the URL token, but the scan counts both as an open paren and never sees the;that ends the declaration, so it missescolor. #972 bounds the scan and fixes the[;and stray)cases; these two need the names taken from the token stream, as tdewolff/parse, css-tree and lightningcss do.