Make WordPress Core

Changeset 30561


Ignore:
Timestamp:
11/25/2014 05:00:36 AM (12 years ago)
Author:
pento
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r30541 r30561  
    26632663
    26642664        // If json_encode() was successful, no need to do more sanity checking.
    2665         if ( false !== $json ) {
     2665        // ... unless we're in an old version of PHP, and json_encode() returned
     2666        // a string containing 'null'. Then we need to do more sanity checking.
     2667        if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) )  {
    26662668                return $json;
    26672669        }
  • trunk/tests/phpunit/tests/functions.php

    r30534 r30561  
    555555                $this->assertEquals( 'aあb', $utf8 );
    556556
    557                 // json_encode() returns different things in different PHP versions.
    558                 // See: https://core.trac.wordpress.org/ticket/30471
    559                 if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) {
    560                         $expected = '"a\u3042b"';
    561                 } else {
    562                         $expected = 'null';
    563                 }
    564 
    565                 $this->assertEquals( $expected, wp_json_encode( $eucjp ) );
     557                $this->assertEquals( '"a\u3042b"', wp_json_encode( $eucjp ) );
    566558
    567559                mb_detect_order( $old_charsets );
    … …  
    583575                $this->assertEquals( 'aあb', $utf8 );
    584576
    585                 // json_encode() returns different things in different PHP versions.
    586                 // See: https://core.trac.wordpress.org/ticket/30471
    587                 if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) {
    588                         $expected = '["c","a\u3042b"]';
    589                 } else {
    590                         $expected = '["c",null]';
    591                 }
    592 
    593                 $this->assertEquals( $expected, wp_json_encode( array( 'c', $eucjp ) ) );
     577                $this->assertEquals( '["c","a\u3042b"]', wp_json_encode( array( 'c', $eucjp ) ) );
    594578
    595579                mb_detect_order( $old_charsets );
Note: See TracChangeset for help on using the changeset viewer.