Remove workaround for PHP bug 66021 (PHP < 5.5.12)
authorFomafix <fomafix@googlemail.com>
Sun, 16 Apr 2017 21:32:02 +0000 (23:32 +0200)
committerMaxSem <maxsem.wiki@gmail.com>
Thu, 31 May 2018 01:14:58 +0000 (01:14 +0000)
The PHP bug 66021 <https://bugs.php.net/bug.php?id=66021> was fixed by
https://github.com/php/php-src/pull/518 and is included in PHP 5.4.28+
and PHP 5.5.12+.
This workaround is not necessary anymore because the minimum PHP
version for MediaWiki is 7.0.0+.

Change-Id: I801eaffc253fd88e0d3c87cfe97777837bd3902d

includes/json/FormatJson.php

index 0c77a7b..acbbf26 100644 (file)
@@ -77,17 +77,6 @@ class FormatJson {
         */
        const STRIP_COMMENTS = 0x400;
 
-       /**
-        * Regex that matches whitespace inside empty arrays and objects.
-        *
-        * This doesn't affect regular strings inside the JSON because those can't
-        * have a real line break (\n) in them, at this point they are already escaped
-        * as the string "\n" which this doesn't match.
-        *
-        * @private
-        */
-       const WS_CLEANUP_REGEX = '/(?<=[\[{])\n\s*+(?=[\]}])/';
-
        /**
         * Characters problematic in JavaScript.
         *
@@ -129,11 +118,6 @@ class FormatJson {
                        $pretty = $pretty ? '    ' : false;
                }
 
-               static $bug66021;
-               if ( $pretty !== false && $bug66021 === null ) {
-                       $bug66021 = json_encode( [], JSON_PRETTY_PRINT ) !== '[]';
-               }
-
                // PHP escapes '/' to prevent breaking out of inline script blocks using '</script>',
                // which is hardly useful when '<' and '>' are escaped (and inadequate), and such
                // escaping negatively impacts the human readability of URLs and similar strings.
@@ -147,10 +131,6 @@ class FormatJson {
                }
 
                if ( $pretty !== false ) {
-                       // Workaround for <https://bugs.php.net/bug.php?id=66021>
-                       if ( $bug66021 ) {
-                               $json = preg_replace( self::WS_CLEANUP_REGEX, '', $json );
-                       }
                        if ( $pretty !== '    ' ) {
                                // Change the four-space indent to a tab indent
                                $json = str_replace( "\n    ", "\n\t", $json );