jenkins-bot has submitted this change and it was merged. Change subject: FormatJson: Skip whitespace cleanup when unnecessary ......................................................................
FormatJson: Skip whitespace cleanup when unnecessary The patch[1] for PHP bug 66021[2], which removes the same undesirable whitespace that WS_CLEANUP_REGEX does, has been merged into php-src. Subsequent PHP versions having the patch shouldn't have to take the 10-20% performance hit from that workaround. [1]: https://github.com/php/php-src/commit/82a4f1a1a287 [2]: https://bugs.php.net/bug.php?id=66021 Change-Id: I717a0e164952cc6ace104f13f6236e86c4ab8b58 --- M includes/json/FormatJson.php 1 file changed, 10 insertions(+), 3 deletions(-) Approvals: Nikerabbit: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/json/FormatJson.php b/includes/json/FormatJson.php index 97d98a4..eb5e632 100644 --- a/includes/json/FormatJson.php +++ b/includes/json/FormatJson.php @@ -136,6 +136,11 @@ * @return string|bool */ private static function encode54( $value, $pretty, $escaping ) { + static $bug66021; + if ( $pretty !== false && $bug66021 === null ) { + $bug66021 = json_encode( array(), 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. @@ -149,9 +154,11 @@ } if ( $pretty !== false ) { - // Remove whitespace inside empty arrays/objects; different JSON encoders - // vary on this, and we want our output to be consistent across implementations. - $json = preg_replace( self::WS_CLEANUP_REGEX, '', $json ); + // Workaround for <https://bugs.php.net/bug.php?id=66021> + // Can be removed once we require PHP >= 5.4.28, 5.5.12, 5.6.0 + 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 ); -- To view, visit https://gerrit.wikimedia.org/r/129631 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I717a0e164952cc6ace104f13f6236e86c4ab8b58 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: PleaseStand <pleasest...@live.com> Gerrit-Reviewer: Anomie <bjor...@wikimedia.org> Gerrit-Reviewer: Chad <ch...@wikimedia.org> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Nikerabbit <niklas.laxst...@gmail.com> Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits