diff --git a/_test/tests/lib/exe/css_css_compress.test.php b/_test/tests/lib/exe/css_css_compress.test.php index 4769684a82bfd4024cb80297c0c5856ece5e054a..807317ca6c2bb2ca7653d7bca1860cfa74e89f18 100644 --- a/_test/tests/lib/exe/css_css_compress.test.php +++ b/_test/tests/lib/exe/css_css_compress.test.php @@ -60,6 +60,14 @@ class css_css_compress_test extends DokuWikiTest { $this->assertEquals('#foo{background-image:url(//foo.bar/baz.jpg);}', css_compress($text)); } + function test_slcom7(){ + $text = '#foo a[href ^="https://"], #foo a[href ^=\'https://\'] { + background-image: url(//foo.bar/baz.jpg); // background-image: url(http://foo.bar/baz.jpg); this is \'all\' "commented" + }'; + $this->assertEquals('#foo a[href ^="https://"],#foo a[href ^=\'https://\']{background-image:url(//foo.bar/baz.jpg);}', css_compress($text)); + } + + function test_hack(){ $text = '/* Mac IE will not see this and continue with inline-block */ /* \\*/ diff --git a/lib/exe/css.php b/lib/exe/css.php index 30d0d18c56d2cb8ffa71f71bc87a24d07890a868..6c1d607514d3a2c0da391df74e7f704c710fdb93 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -602,30 +602,47 @@ function css_comment_cb($matches){ function css_onelinecomment_cb($matches) { $line = $matches[0]; - $out = ''; $i = 0; $len = strlen($line); + while ($i< $len){ $nextcom = strpos($line, '//', $i); $nexturl = stripos($line, 'url(', $i); if($nextcom === false) { // no more comments, we're done - $out .= substr($line, $i, $len-$i); + $i = $len; break; } + + // keep any quoted string that starts before a comment + $nextsqt = strpos($line, "'", $i); + $nextdqt = strpos($line, '"', $i); + if(min($nextsqt, $nextdqt) < $nextcom) { + $skipto = false; + if($nextsqt !== false && ($nextdqt === false || $nextsqt < $nextdqt)) { + $skipto = strpos($line, "'", $nextsqt+1) +1; + } else if ($nextdqt !== false) { + $skipto = strpos($line, '"', $nextdqt+1) +1; + } + + if($skipto !== false) { + $i = $skipto; + continue; + } + } + if($nexturl === false || $nextcom < $nexturl) { // no url anymore, strip comment and be done - $out .= substr($line, $i, $nextcom-$i); + $i = $nextcom; break; } + // we have an upcoming url - $urlclose = strpos($line, ')', $nexturl); - $out .= substr($line, $i, $urlclose-$i); - $i = $urlclose; + $i = strpos($line, ')', $nexturl); } - return $out; + return substr($line, 0, $i); } //Setup VIM: ex: et ts=4 :