tubalmartin / YUI-CSS-compressor-PHP-port

A PHP port of the YUI CSS compressor.
230 stars 34 forks source link

Breakage when minifying at-import with unquoted urls containing semicolons #45

Closed zytzagoo closed 6 years ago

zytzagoo commented 6 years ago

Here's a testcase that fails with current master:

@import url(//example.org/foo.css?a&b);
@import url(//example.org/bar.css);

Expected output:

@import url(//example.org/foo.css?a&b);@import url(//example.org/bar.css);

Actual output:

@import url(//example.org/foo.css?a&@import url(//example.org/bar.css);b);

Diff highlight:

Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'@import url(//example.org/foo.css?a&b);@import url(//example.org/bar.css);'
+'@import url(//example.org/foo.css?a&@import url(//example.org/bar.css);b);'

When urls are quoted, the problem doesn't occur (because processStringsCallback() captures and later restores the url "tokens"). However, I cannot control the inputs being given to Minifier.

Do you have any pointers on how to best approach fixing this? Is this something you think needs fixing at all?

I have a branch ready for a PR over at my fork (with the test suite passing), as this is currently a showstopper for getting the latest version integrated into Autoptimize, however, there's probably a better/smarter way to go about fixing this -- I just needed to get something that works quickly...

tubalmartin commented 6 years ago

Thank you for reporting the issue extensively. I will review this for sure :)

tubalmartin commented 6 years ago

Umm yes this is a valid issue. A semicolon is a reserved character in an URI and CSSmin should support it in import at rules. I'll fix this.

tubalmartin commented 6 years ago

Fixed in v4.1.1