diff options
author | Andreas Gohr <andi@splitbrain.org> | 2014-05-14 19:24:01 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2014-05-14 19:24:01 +0200 |
commit | 918a4468877109c2ba2f82fa4e1a225a4738ed9a (patch) | |
tree | fac9b3bb89faf60895913960499faa727eab3e20 | |
parent | cfb2335aca014812dc45fc4dc5a4289456e66e4c (diff) | |
download | rpg-918a4468877109c2ba2f82fa4e1a225a4738ed9a.tar.gz rpg-918a4468877109c2ba2f82fa4e1a225a4738ed9a.tar.bz2 |
don't treat double slashes as comments when used in string
This avoids treating double slashes as single line comments in CSS when
they are used in a filter or content string.
closes #638
-rw-r--r-- | _test/tests/lib/exe/css_css_compress.test.php | 8 | ||||
-rw-r--r-- | lib/exe/css.php | 31 |
2 files changed, 32 insertions, 7 deletions
diff --git a/_test/tests/lib/exe/css_css_compress.test.php b/_test/tests/lib/exe/css_css_compress.test.php index 4769684a8..807317ca6 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 30d0d18c5..6c1d60751 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 : |