summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_test/cases/lib/exe/css_css_compress.test.php19
-rw-r--r--lib/exe/css.php8
2 files changed, 23 insertions, 4 deletions
diff --git a/_test/cases/lib/exe/css_css_compress.test.php b/_test/cases/lib/exe/css_css_compress.test.php
index 68d19fae8..026caad3c 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 5973991ef..715d32885 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);