Closed gmcgibbon closed 1 year 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.
/(.[^:]*)\s*:\s*(?m:(.+))(;?\s*\Z)/i
I'm not a regex pro so I'm not sure if this is the best solution. Thoughts?
@grosser any chance you could take a look at this PR?
looks good, can you make rubocop happy too ?
@grosser thanks! @gmcgibbon just pushed the fix.
1.14.0 🎉
❤️
Currently, parsing doesn't work properly for CSS rules with multiline URL values. Here's what happens:
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?