Skip to content
Snippets Groups Projects
Commit 918a4468 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

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
parent cfb2335a
No related branches found
No related tags found
No related merge requests found
......@@ -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 */
/* \\*/
......
......@@ -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 :
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment