premailer / css_parser

Ruby CSS Parser
Other
279 stars 110 forks source link

Parsing failure with minified `@media(xxx){...}` rule #139

Closed jdelStrother closed 1 year ago

jdelStrother commented 1 year ago

My CSS minifier reduces this -

@media (prefers-color-scheme: dark) {
  a { color: red; }
}

to this -

@media(prefers-color-scheme:dark){a{color:red}}

which CSSParser fails on, losing the @media rule entirely:

parser = CssParser::Parser.new
parser.load_string! "@media(prefers-color-scheme:dark){a{color:red}}"
puts parser.to_s # => "a {\ncolor: red;\n}\n"

Including a space after @media fixes it, so the bug is avoidable by altering my source to @media screen and (prefers-color-scheme: dark). @media(prefers-color-scheme:dark) { ... } ought to be valid on its own though, right?

grosser commented 1 year ago

yeah it should be valid, thx for the bug report I have no idea how to fix that though, so if you find a way please send a PR!