public static function minify( $css ) {
return trim(
str_replace(
- [ '; ', ': ', ' {', '{ ', ', ', '} ', ';}' ],
- [ ';', ':', '{', '{', ',', '}', '}' ],
+ [ '; ', ': ', ' {', '{ ', ', ', '} ', ';}', '( ', ' )', '[ ', ' ]' ],
+ [ ';', ':', '{', '{', ',', '}', '}', '(', ')', '[', ']' ],
preg_replace( [ '/\s+/', '/\/\*.*?\*\//s' ], [ ' ', '' ], $css )
)
);
[ "foo { content: '\"'; }", "foo{content:'\"'}" ],
// - Whitespace in string values
[ 'foo { content: " "; }', 'foo{content:" "}' ],
+
+ // Whitespaces after opening and before closing parentheses and brackets
+ [ 'a:not( [ href ] ) { prop: url( foobar.png ); }', 'a:not([href]){prop:url(foobar.png)}' ],
+
+ // Ensure that the invalid "url (" will not become the valid "url(" by minification
+ [ 'foo { prop: url ( foobar.png ); }', 'foo{prop:url (foobar.png)}' ],
];
}