CSSMin: Do not escape U+FFFD as code point
authorFomafix <fomafix@googlemail.com>
Thu, 17 May 2018 10:18:27 +0000 (12:18 +0200)
committerFomafix <fomafix@googlemail.com>
Thu, 17 May 2018 10:22:59 +0000 (12:22 +0200)
The current editors draft from 23 April 2018 does not require to escape
the REPLACEMENT CHARACTER (U+FFFD) as code point anymore.

https://drafts.csswg.org/cssom/#serialize-a-string
  If the character is NULL (U+0000), then the REPLACEMENT CHARACTER
  (U+FFFD).

https://www.w3.org/TR/2016/WD-cssom-1-20160317/#serialize-a-string
  If the character is NULL (U+0000), then the REPLACEMENT CHARACTER
  (U+FFFD) escaped as code point.

Change-Id: Ia67e89b3c9561ca29e133d61a2eca8f3db306d8c

includes/libs/CSSMin.php
tests/phpunit/includes/libs/CSSMinTest.php

index a6014b1..c227268 100644 (file)
@@ -173,13 +173,13 @@ class CSSMin {
 
        /**
         * Serialize a string (escape and quote) for use as a CSS string value.
-        * https://www.w3.org/TR/2016/WD-cssom-1-20160317/#serialize-a-string
+        * https://drafts.csswg.org/cssom/#serialize-a-string
         *
         * @param string $value
         * @return string
         */
        public static function serializeStringValue( $value ) {
-               $value = strtr( $value, [ "\0" => "\\fffd ", '\\' => '\\\\', '"' => '\\"' ] );
+               $value = strtr( $value, [ "\0" => "\xEF\xBF\xBD", '\\' => '\\\\', '"' => '\\"' ] );
                $value = preg_replace_callback( '/[\x01-\x1f\x7f]/', function ( $match ) {
                        return '\\' . base_convert( ord( $match[0] ), 10, 16 ) . ' ';
                }, $value );
index dabf66b..3876a68 100644 (file)
@@ -35,7 +35,7 @@ class CSSMinTest extends MediaWikiTestCase {
        public static function provideSerializeStringValue() {
                return [
                        [ 'Hello World!', '"Hello World!"' ],
-                       [ "Null\0Null", "\"Null\\fffd Null\"" ],
+                       [ "Null\0Null", "\"Null\xEF\xBF\xBDNull\"" ],
                        [ '"', '"\\""' ],
                        [ "'", '"\'"' ],
                        [ "\\", '"\\\\"' ],