diff options
author | Andreas Gohr <andi@splitbrain.org> | 2014-03-05 19:37:43 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2014-03-05 19:37:43 +0100 |
commit | fe5a50c39e9bd837f887ea7ad8335717a6c6ab92 (patch) | |
tree | 95558cb4cb0359b7e5c0e1eb9b280fe1b03bbda4 /lib/exe | |
parent | 0499ebedfee66081086cd4ec5951365341072c88 (diff) | |
download | rpg-fe5a50c39e9bd837f887ea7ad8335717a6c6ab92.tar.gz rpg-fe5a50c39e9bd837f887ea7ad8335717a6c6ab92.tar.bz2 |
fix single line comments in CSS compression
double slashes in url() always have to be ignored
Diffstat (limited to 'lib/exe')
-rw-r--r-- | lib/exe/css.php | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php index cab7384b2..0a2a5a406 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -552,7 +552,7 @@ function css_compress($css){ $css = preg_replace_callback('#(/\*)(.*?)(\*/)#s','css_comment_cb',$css); //strip (incorrect but common) one line comments - $css = preg_replace('/(?<!:)\/\/.*$/m','',$css); + $css = preg_replace_callback('/^.*\/\/.*$/m','css_onelinecomment_cb',$css); // strip whitespaces $css = preg_replace('![\r\n\t ]+!',' ',$css); @@ -588,4 +588,46 @@ function css_comment_cb($matches){ return $matches[0]; } +/** + * Callback for css_compress() + * + * Strips one line comments but makes sure it will not destroy url() constructs with slashes + * + * @param $matches + * @return string + */ +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); + break; + } + if($nexturl === false) { + // no url anymore, strip comment and be done + $out .= substr($line, $i, $nextcom-$i); + break; + } + if($nextcom < $nexturl) { + // that comment comments out the url + $out .= substr($line, $i, $len-$i); + break; + } + // we have an upcoming url + $urlclose = strpos($line, ')', $nexturl); + $out .= substr($line, $i, $urlclose-$i); + $i = $urlclose; + } + + return $out; +} + //Setup VIM: ex: et ts=4 : |