Make WordPress Core

Ticket #30471: 30471.diff

File 30471.diff, 1.4 KB (added by pento, 10 years ago)
  • src/wp-includes/functions.php

     
    26622662        $json = call_user_func_array( 'json_encode', $args );
    26632663
    26642664        // If json_encode() was successful, no need to do more sanity checking.
    2665         if ( false !== $json ) {
     2665        if ( false !== $json && 'null' !== $json ) {
    26662666                return $json;
    26672667        }
    26682668
     2669        // json_encode() can sometimes return 'null' for strings it couldn't handle,
     2670        // so we should only return 'null' if null was given to us.
     2671        if ( null === $data && 'null' === $json ) {
     2672                return null;
     2673        }
     2674
    26692675        try {
    26702676                $args[0] = _wp_json_sanity_check( $data, $depth );
    26712677        } catch ( Exception $e ) {
  • tests/phpunit/tests/functions.php

     
    554554
    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                 }
     557                $this->assertEquals( '"a\u3042b"', wp_json_encode( $eucjp ) );
    564558
    565                 $this->assertEquals( $expected, wp_json_encode( $eucjp ) );
    566 
    567559                mb_detect_order( $old_charsets );
    568560        }
    569561