When `json_encode()` returns a JSON string containing `'null'` in PHP 5.4 or earlier, `wp_json_encode()` will now sanity check the data, as older versions of PHP failed to encode non UTF-8 characters correctly, instead returning `'null'`.
Fixes #30471. git-svn-id: https://develop.svn.wordpress.org/trunk@30561 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
a6b7826831
commit
0cb93dd166
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue