milkshakesoftware/PreMailer.Net

Bug in comment regex, fix in issue description

AbstractionsAs opened this issue · 1 comments

Hi,

There's a bug in the comment regex in the CSS parser, but it's easily fixed.

Imagine the following CSS:

img.logo {
  -premailer-src: "https://example.com/logo.png";
  -premailer-height: 80px;
  -premailer-width: 100px;
  width: 100px;
  height: 100px;
}

This is stripped by the comment regex and turns into a long string with all the values.

If the regex (?:/\*(.|[\r\n])*?\*/)|(?:(?<!url\s*\([^)]*)//.*) is changed to (?:/\*(.|[\r\n])*?\*/)|(?:(?<!url\s*\([^)]*)(?<!\:)//.*) in CssParser.cs, // sequences that are immediatly preceded by : will not be matched, and everything will work

HI @AbstractionsAs ,

This will fix this case. However you can do a protocol agnostic url which this will not catch. ex.

 -premailer-src: "//example.com/logo.png";

I think the regex should probably be replaced by a parser for better context. However we might be able to get away with a pretty clever regex expression.