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:
Gary Pendergast
2014-11-25 05:00:36 +00:00
parent a6b7826831
commit 0cb93dd166
2 changed files with 5 additions and 19 deletions

View File

@@ -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;
}