From: Fomafix Date: Wed, 6 Dec 2017 16:16:41 +0000 (+0100) Subject: CSSMin: Trim whitespace from attribute selectors and url tokens X-Git-Tag: 1.31.0-rc.0~527 X-Git-Url: https://git.cyclocoop.org/%20%27.%28%24debut%20%20%20%24par_page%29.%27?a=commitdiff_plain;h=5ca659b287a1ef7755729de60c1bcc5ff4a79c76;p=lhc%2Fweb%2Fwiklou.git CSSMin: Trim whitespace from attribute selectors and url tokens * Trim whitespaces after opening and before closing parentheses and brackets. * Ensure by test case that the invalid "url (" will not become the valid "url(" by minification. This change also prevents the parsing problem in Firefox 57.0 https://bugzilla.mozilla.org/1418152 which is fixed in Firefox 57.0.1. Change-Id: I804477ba7c6363f0e964fc8c7c0bc74d2d4c1a0d --- diff --git a/includes/libs/CSSMin.php b/includes/libs/CSSMin.php index f2c7ed29f0..3d1c8b800d 100644 --- a/includes/libs/CSSMin.php +++ b/includes/libs/CSSMin.php @@ -535,8 +535,8 @@ class CSSMin { public static function minify( $css ) { return trim( str_replace( - [ '; ', ': ', ' {', '{ ', ', ', '} ', ';}' ], - [ ';', ':', '{', '{', ',', '}', '}' ], + [ '; ', ': ', ' {', '{ ', ', ', '} ', ';}', '( ', ' )', '[ ', ' ]' ], + [ ';', ':', '{', '{', ',', '}', '}', '(', ')', '[', ']' ], preg_replace( [ '/\s+/', '/\/\*.*?\*\//s' ], [ ' ', '' ], $css ) ) ); diff --git a/tests/phpunit/includes/libs/CSSMinTest.php b/tests/phpunit/includes/libs/CSSMinTest.php index 89cf68fcd4..667eb0ace6 100644 --- a/tests/phpunit/includes/libs/CSSMinTest.php +++ b/tests/phpunit/includes/libs/CSSMinTest.php @@ -149,6 +149,12 @@ class CSSMinTest extends MediaWikiTestCase { [ "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)}' ], ]; }