diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 0fb2117835..9f229291a7 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -2662,7 +2662,9 @@ function wp_json_encode( $data, $options = 0, $depth = 512 ) { $json = call_user_func_array( 'json_encode', $args ); // If json_encode() was successful, no need to do more sanity checking. - if ( false !== $json ) { + // ... unless we're in an old version of PHP, and json_encode() returned + // a string containing 'null'. Then we need to do more sanity checking. + if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) ) { return $json; } diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 7b2870c6e5..1edd143fbc 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -554,15 +554,7 @@ class Tests_Functions extends WP_UnitTestCase { $this->assertEquals( 'aあb', $utf8 ); - // json_encode() returns different things in different PHP versions. - // See: https://core.trac.wordpress.org/ticket/30471 - if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) { - $expected = '"a\u3042b"'; - } else { - $expected = 'null'; - } - - $this->assertEquals( $expected, wp_json_encode( $eucjp ) ); + $this->assertEquals( '"a\u3042b"', wp_json_encode( $eucjp ) ); mb_detect_order( $old_charsets ); } @@ -582,15 +574,7 @@ class Tests_Functions extends WP_UnitTestCase { $this->assertEquals( 'aあb', $utf8 ); - // json_encode() returns different things in different PHP versions. - // See: https://core.trac.wordpress.org/ticket/30471 - if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) { - $expected = '["c","a\u3042b"]'; - } else { - $expected = '["c",null]'; - } - - $this->assertEquals( $expected, wp_json_encode( array( 'c', $eucjp ) ) ); + $this->assertEquals( '["c","a\u3042b"]', wp_json_encode( array( 'c', $eucjp ) ) ); mb_detect_order( $old_charsets ); }