premailer / css_parser

Ruby CSS Parser
Other
279 stars 110 forks source link

Fix parsing of multiline URL values for rule sets #97

Closed gmcgibbon closed 1 year ago

gmcgibbon commented 6 years ago

Currently, parsing doesn't work properly for CSS rules with multiline URL values. Here's what happens:

font_face = "@font-face {\n src: url(https://example.com/font.woff2), \n url(https://example.com/font.woff); } \n"
CssParser::Parser.new.tap { |parser| parser.add_block!(font_face) }.to_s
# => "@font-face {\n://example.com/font.woff2),url(https: //example.com/font.woff);\n}\n"

This is due to the regex here: https://github.com/premailer/css_parser/blob/57647747cb8b9eb517b0e70949b3e23b777645f5/lib/css_parser/rule_set.rb#L501

Amending this regex to /(.[^:]*)\s*:\s*(?m:(.+))(;?\s*\Z)/i (which essentially allows multiline capturing of a CSS rule's value capture group) fixes this issue.

I'm not a regex pro so I'm not sure if this is the best solution. Thoughts?

casperisfine commented 1 year ago

@grosser any chance you could take a look at this PR?

grosser commented 1 year ago

looks good, can you make rubocop happy too ?

casperisfine commented 1 year ago

@grosser thanks! @gmcgibbon just pushed the fix.

grosser commented 1 year ago

1.14.0 🎉

casperisfine commented 1 year ago

❤️