diff --git a/_test/cases/lib/exe/css_css_compress.test.php b/_test/cases/lib/exe/css_css_compress.test.php index 68d19fae84ba1257be95bb32b034c42125a731bd..026caad3c495c00b87d3b42be19b2e7811d360a9 100644 --- a/_test/cases/lib/exe/css_css_compress.test.php +++ b/_test/cases/lib/exe/css_css_compress.test.php @@ -21,6 +21,25 @@ class css_css_compress_test extends UnitTestCase { $this->assertEqual(css_compress($text), '#comment/* */{color:lime;}'); } + function test_slcom1(){ + $text = '// this is a comment'; + $this->assertEqual(css_compress($text), ''); + } + + function test_slcom2(){ + $text = '#foo { + color: lime; // another comment + }'; + $this->assertEqual(css_compress($text), '#foo{color:lime;}'); + } + + function test_slcom3(){ + $text = '#foo { + background-image: url(http://foo.bar/baz.jpg); + }'; + $this->assertEqual(css_compress($text), '#foo{background-image:url(http://foo.bar/baz.jpg);}'); + } + 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 5973991ef493e0d503642ba470e85028dbdf88c5..715d32885bad86678f1938af0c173923d4e473e8 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -241,16 +241,16 @@ function css_pluginstyles($mode='screen'){ * @author Andreas Gohr <andi@splitbrain.org> */ function css_compress($css){ + //strip comments through a callback + $css = preg_replace_callback('#(/\*)(.*?)(\*/)#s','css_comment_cb',$css); + //strip (incorrect but common) one line comments - $css = preg_replace('!//.*$!m','',$css); + $css = preg_replace('/(?<!:)\/\/.*$/m','',$css); // strip whitespaces $css = preg_replace('![\r\n\t ]+!',' ',$css); $css = preg_replace('/ ?([:;,{}\/]) ?/','\\1',$css); - //strip comments through a callback - $css = preg_replace_callback('#(/\*)(.*?)(\*/)#s','css_comment_cb',$css); - // shorten colors $css = preg_replace("/#([0-9a-fA-F]{1})\\1([0-9a-fA-F]{1})\\2([0-9a-fA-F]{1})\\3/", "#\\1\\2\\3",$css);