From: Roan Kattouw Date: Thu, 14 Sep 2017 18:32:07 +0000 (-0700) Subject: CSSMin: Mangle whitespace in embedded SVGs X-Git-Tag: 1.31.0-rc.0~2035^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/gestion/rappel_supprimer.php?a=commitdiff_plain;h=dfd42d2653ea9ff2ca05dab7cd6f2285abba9d08;p=lhc%2Fweb%2Fwiklou.git CSSMin: Mangle whitespace in embedded SVGs Convert newlines and tabs to spaces (which can be unencoded), and consolidate runs of multiple spaces into a single space. Also remove any leading and trailing spaces that might result (most files end in a newline, for example). Bug: T175318 Change-Id: Ic66c6acb37079cae84dd80ab2d5f2c829cf2df96 --- diff --git a/includes/libs/CSSMin.php b/includes/libs/CSSMin.php index adaae178f5..a9c021e697 100644 --- a/includes/libs/CSSMin.php +++ b/includes/libs/CSSMin.php @@ -150,7 +150,14 @@ class CSSMin { '%3A' => ':', // Unencode colons '%3D' => '=', // Unencode equals signs '%22' => '"', // Unencode double quotes + '%0A' => ' ', // Change newlines to spaces + '%0D' => ' ', // Change carriage returns to spaces + '%09' => ' ', // Change tabs to spaces ] ); + // Consolidate runs of multiple spaces in a row + $encoded = preg_replace( '/ {2,}/', ' ', $encoded ); + // Remove leading and trailing spaces + $encoded = preg_replace( '/^ | $/', '', $encoded ); $uri = 'data:' . $type . ',' . $encoded; if ( !$ie8Compat || strlen( $uri ) < self::DATA_URI_SIZE_LIMIT ) { return $uri; diff --git a/tests/phpunit/includes/libs/CSSMinTest.php b/tests/phpunit/includes/libs/CSSMinTest.php index 62f990b911..a770fa45a8 100644 --- a/tests/phpunit/includes/libs/CSSMinTest.php +++ b/tests/phpunit/includes/libs/CSSMinTest.php @@ -271,9 +271,9 @@ class CSSMinTest extends MediaWikiTestCase { // data: URIs for red.gif, green.gif, circle.svg $red = 'data:image/gif;base64,R0lGODlhAQABAIAAAP8AADAAACwAAAAAAQABAAACAkQBADs='; $green = 'data:image/gif;base64,R0lGODlhAQABAIAAAACAADAAACwAAAAAAQABAAACAkQBADs='; - $svg = 'data:image/svg+xml,%3C%3Fxml version="1.0" encoding="UTF-8"%3F%3E%0A' + $svg = 'data:image/svg+xml,%3C%3Fxml version="1.0" encoding="UTF-8"%3F%3E ' . '%3Csvg xmlns="http://www.w3.org/2000/svg" width="8" height=' - . '"8"%3E%0A%09%3Ccircle cx="4" cy="4" r="2"/%3E%0A%3C/svg%3E%0A'; + . '"8"%3E %3Ccircle cx="4" cy="4" r="2"/%3E %3C/svg%3E'; // @codingStandardsIgnoreStart Generic.Files.LineLength return [