Ticket #28786: 28786.11.diff
| File 28786.11.diff, 18.6 KB (added by , 12 years ago) |
|---|
-
src/wp-admin/customize.php
271 271 272 272 ?> 273 273 <script type="text/javascript"> 274 var _wpCustomizeSettings = <?php echo json_encode( $settings ); ?>;274 var _wpCustomizeSettings = <?php echo wp_json_encode( $settings ); ?>; 275 275 </script> 276 276 </div> 277 277 </body> -
src/wp-admin/includes/ajax-actions.php
286 286 ); 287 287 } 288 288 289 wp_die( json_encode( $return ) );289 wp_die( wp_json_encode( $return ) ); 290 290 } 291 291 292 292 /** … … 1365 1365 1366 1366 $markup = ob_get_clean(); 1367 1367 1368 echo json_encode(array(1368 echo wp_json_encode(array( 1369 1369 'replace-id' => $type . '-' . $item->name, 1370 1370 'markup' => $markup, 1371 1371 )); … … 1394 1394 if ( ! isset( $results ) ) 1395 1395 wp_die( 0 ); 1396 1396 1397 echo json_encode( $results );1397 echo wp_json_encode( $results ); 1398 1398 echo "\n"; 1399 1399 1400 1400 wp_die(); … … 1840 1840 if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ) ) ) { 1841 1841 $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'], false ); 1842 1842 if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) { 1843 echo json_encode( array(1843 echo wp_json_encode( array( 1844 1844 'success' => false, 1845 1845 'data' => array( 1846 1846 'message' => __( 'The uploaded file is not a valid image. Please try again.' ), … … 1855 1855 $attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data ); 1856 1856 1857 1857 if ( is_wp_error( $attachment_id ) ) { 1858 echo json_encode( array(1858 echo wp_json_encode( array( 1859 1859 'success' => false, 1860 1860 'data' => array( 1861 1861 'message' => $attachment_id->get_error_message(), … … 1877 1877 if ( ! $attachment = wp_prepare_attachment_for_js( $attachment_id ) ) 1878 1878 wp_die(); 1879 1879 1880 echo json_encode( array(1880 echo wp_json_encode( array( 1881 1881 'success' => true, 1882 1882 'data' => $attachment, 1883 1883 ) ); … … 1902 1902 switch ( $_POST['do'] ) { 1903 1903 case 'save' : 1904 1904 $msg = wp_save_image($attachment_id); 1905 $msg = json_encode($msg);1905 $msg = wp_json_encode($msg); 1906 1906 wp_die( $msg ); 1907 1907 break; 1908 1908 case 'scale' : -
src/wp-admin/includes/class-wp-list-table.php
1058 1058 $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] ); 1059 1059 } 1060 1060 1061 die( json_encode( $response ) );1061 die( wp_json_encode( $response ) ); 1062 1062 } 1063 1063 1064 1064 /** … … 1075 1075 ) 1076 1076 ); 1077 1077 1078 printf( "<script type='text/javascript'>list_args = %s;</script>\n", json_encode( $args ) );1078 printf( "<script type='text/javascript'>list_args = %s;</script>\n", wp_json_encode( $args ) ); 1079 1079 } 1080 1080 } -
src/wp-admin/includes/class-wp-themes-list-table.php
273 273 if ( is_array( $extra_args ) ) 274 274 $args = array_merge( $args, $extra_args ); 275 275 276 printf( "<script type='text/javascript'>var theme_list_args = %s;</script>\n", json_encode( $args ) );276 printf( "<script type='text/javascript'>var theme_list_args = %s;</script>\n", wp_json_encode( $args ) ); 277 277 parent::_js_vars(); 278 278 } 279 279 } -
src/wp-admin/includes/media.php
1826 1826 $large_size_w = 1024; 1827 1827 ?> 1828 1828 var resize_height = <?php echo $large_size_h; ?>, resize_width = <?php echo $large_size_w; ?>, 1829 wpUploaderInit = <?php echo json_encode($plupload_init); ?>;1829 wpUploaderInit = <?php echo wp_json_encode( $plupload_init ); ?>; 1830 1830 </script> 1831 1831 1832 1832 <div id="plupload-upload-ui" class="hide-if-no-js"> -
src/wp-admin/includes/misc.php
621 621 <div class="color-option <?php echo ( $color == $current_color ) ? 'selected' : ''; ?>"> 622 622 <input name="admin_color" id="admin_color_<?php echo esc_attr( $color ); ?>" type="radio" value="<?php echo esc_attr( $color ); ?>" class="tog" <?php checked( $color, $current_color ); ?> /> 623 623 <input type="hidden" class="css_url" value="<?php echo esc_url( $color_info->url ); ?>" /> 624 <input type="hidden" class="icon_colors" value="<?php echo esc_attr( json_encode( array( 'icons' => $color_info->icon_colors ) ) ); ?>" />624 <input type="hidden" class="icon_colors" value="<?php echo esc_attr( wp_json_encode( array( 'icons' => $color_info->icon_colors ) ) ); ?>" /> 625 625 <label for="admin_color_<?php echo esc_attr( $color ); ?>"><?php echo esc_html( $color_info->name ); ?></label> 626 626 <table class="color-palette"> 627 627 <tr> … … 665 665 $icon_colors = array( 'base' => '#999', 'focus' => '#2ea2cc', 'current' => '#fff' ); 666 666 } 667 667 668 echo '<script type="text/javascript">var _wpColorScheme = ' . json_encode( array( 'icons' => $icon_colors ) ) . ";</script>\n";668 echo '<script type="text/javascript">var _wpColorScheme = ' . wp_json_encode( array( 'icons' => $icon_colors ) ) . ";</script>\n"; 669 669 } 670 670 add_action( 'admin_head', 'wp_color_scheme_settings' ); 671 671 -
src/wp-admin/includes/nav-menu.php
356 356 if ( 'markup' == $response_format ) { 357 357 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args ); 358 358 } elseif ( 'json' == $response_format ) { 359 echo json_encode(359 echo wp_json_encode( 360 360 array( 361 361 'ID' => $object_id, 362 362 'post_title' => get_the_title( $object_id ), … … 373 373 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args ); 374 374 } elseif ( 'json' == $response_format ) { 375 375 $post_obj = get_term( $object_id, $object_type ); 376 echo json_encode(376 echo wp_json_encode( 377 377 array( 378 378 'ID' => $object_id, 379 379 'post_title' => $post_obj->name, … … 401 401 $var_by_ref = get_the_ID(); 402 402 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args ); 403 403 } elseif ( 'json' == $response_format ) { 404 echo json_encode(404 echo wp_json_encode( 405 405 array( 406 406 'ID' => get_the_ID(), 407 407 'post_title' => get_the_title(), … … 422 422 if ( 'markup' == $response_format ) { 423 423 echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args ); 424 424 } elseif ( 'json' == $response_format ) { 425 echo json_encode(425 echo wp_json_encode( 426 426 array( 427 427 'ID' => $term->term_id, 428 428 'post_title' => $term->name, -
src/wp-admin/includes/template.php
1954 1954 <script type="text/javascript"> 1955 1955 //<![CDATA[ 1956 1956 (function($){ 1957 var options = <?php echo json_encode( $args ); ?>, setup;1957 var options = <?php echo wp_json_encode( $args ); ?>, setup; 1958 1958 1959 1959 if ( ! options ) 1960 1960 return; -
src/wp-includes/class-wp-customize-manager.php
510 510 511 511 ?> 512 512 <script type="text/javascript"> 513 var _wpCustomizeSettings = <?php echo json_encode( $settings ); ?>;513 var _wpCustomizeSettings = <?php echo wp_json_encode( $settings ); ?>; 514 514 </script> 515 515 <?php 516 516 } -
src/wp-includes/class-wp-customize-widgets.php
740 740 $wp_scripts->add_data( 741 741 'customize-widgets', 742 742 'data', 743 sprintf( 'var _wpCustomizeWidgetsSettings = %s;', json_encode( $settings ) )743 sprintf( 'var _wpCustomizeWidgetsSettings = %s;', wp_json_encode( $settings ) ) 744 744 ); 745 745 } 746 746 … … 1055 1055 1056 1056 ?> 1057 1057 <script type="text/javascript"> 1058 var _wpWidgetCustomizerPreviewSettings = <?php echo json_encode( $settings ); ?>;1058 var _wpWidgetCustomizerPreviewSettings = <?php echo wp_json_encode( $settings ); ?>; 1059 1059 </script> 1060 1060 <?php 1061 1061 } -
src/wp-includes/class-wp-editor.php
499 499 ); 500 500 501 501 if ( ! empty( $mce_external_plugins ) ) { 502 self::$first_init['external_plugins'] = json_encode( $mce_external_plugins );502 self::$first_init['external_plugins'] = wp_json_encode( $mce_external_plugins ); 503 503 } 504 504 505 505 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; … … 985 985 $mce_translation['_dir'] = 'rtl'; 986 986 } 987 987 988 return "tinymce.addI18n( '$mce_locale', " . json_encode( $mce_translation ) . ");\n" .988 return "tinymce.addI18n( '$mce_locale', " . wp_json_encode( $mce_translation ) . ");\n" . 989 989 "tinymce.ScriptLoader.markDone( '$baseurl/langs/$mce_locale.js' );\n"; 990 990 } 991 991 -
src/wp-includes/class.wp-scripts.php
167 167 $l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8'); 168 168 } 169 169 170 $script = "var $object_name = " . json_encode($l10n) . ';';170 $script = "var $object_name = " . wp_json_encode( $l10n ) . ';'; 171 171 172 172 if ( !empty($after) ) 173 173 $script .= "\n$after;"; -
src/wp-includes/functions.php
2613 2613 } 2614 2614 2615 2615 /** 2616 * Encode a variable into JSON, with some sanity checks 2617 * 2618 * @since 4.1.0 2619 * 2620 * @param mixed $data Variable (usually an array or object) to encode as JSON 2621 * @param int $options Options to be passed to json_encode(). Default 0. 2622 * @param int $depth Maximum depth to walk through $data. Must be greater than 0, default 512.t 2623 * 2624 * @return bool|string The JSON encoded string, or false if it cannot be encoded 2625 */ 2626 function wp_json_encode( $data, $options = 0, $depth = 512 ) { 2627 // json_encode has had extra params added over the years. 2628 // $options was added in 5.3, and $depth in 5.5. 2629 // We need to make sure we call it with the correct arguments. 2630 if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) { 2631 $args = array( $data, $options, $depth ); 2632 } else if ( version_compare( PHP_VERSION, '5.3', '>=' ) ) { 2633 $args = array( $data, $options ); 2634 } else { 2635 $args = array( $data ); 2636 } 2637 2638 $json = call_user_func_array( 'json_encode', $args ); 2639 2640 if ( false !== $json ) { 2641 // If json_encode was successful, no need to do more sanity checking 2642 return $json; 2643 } 2644 2645 try { 2646 $args[0] = _wp_json_sanity_check( $data, $depth ); 2647 } catch ( Exception $e ) { 2648 return false; 2649 } 2650 2651 return call_user_func_array( 'json_encode', $args ); 2652 } 2653 2654 /** 2655 * @ignore 2656 */ 2657 function _wp_json_sanity_check( $data, $depth ) { 2658 if ( $depth < 0 ) { 2659 throw new Exception( 'Reached depth limit' ); 2660 } 2661 2662 if ( is_array( $data ) ) { 2663 $output = array(); 2664 foreach ( $data as $id => $el ) { 2665 // Don't forget to sanitize the ID! 2666 if ( is_string( $id ) ) { 2667 $clean_id = _wp_json_convert_string( $id ); 2668 } else { 2669 $clean_id = $id; 2670 } 2671 2672 // Check the element type, so that we're only recursing if we really have to 2673 if ( is_array( $el ) || is_object( $el ) ) { 2674 $output[ $clean_id ] = _wp_json_sanity_check( $el, $depth - 1 ); 2675 } else if ( is_string( $el ) ) { 2676 $output[ $clean_id ] = _wp_json_convert_string( $el ); 2677 } else { 2678 $output[ $clean_id ] = $el; 2679 } 2680 } 2681 } else if ( is_object( $data ) ) { 2682 $output = new stdClass; 2683 foreach ( $data as $id => $el ) { 2684 if ( is_string( $id ) ) { 2685 $clean_id = _wp_json_convert_string( $id ); 2686 } else { 2687 $clean_id = $id; 2688 } 2689 2690 if ( is_array( $el ) || is_object( $el ) ) { 2691 $output->$clean_id = _wp_json_sanity_check( $el, $depth - 1 ); 2692 } else if ( is_string( $el ) ) { 2693 $output->$clean_id = _wp_json_convert_string( $el ); 2694 } else { 2695 $output->$clean_id = $el; 2696 } 2697 } 2698 } else if ( is_string( $data ) ) { 2699 return _wp_json_convert_string( $data ); 2700 } else { 2701 return $data; 2702 } 2703 2704 return $output; 2705 } 2706 2707 /** 2708 * @ignore 2709 */ 2710 function _wp_json_convert_string( $string ) { 2711 if ( function_exists( 'mb_convert_encoding' ) ) { 2712 $encoding = mb_detect_encoding( $string ); 2713 if ( $encoding ) { 2714 return mb_convert_encoding( $string, 'UTF-8', $encoding ); 2715 } else { 2716 return mb_convert_encoding( $string, 'UTF-8', 'UTF-8' ); 2717 } 2718 } else { 2719 return wp_check_invalid_utf8( $data, true ); 2720 } 2721 } 2722 2723 /** 2616 2724 * Send a JSON response back to an Ajax request. 2617 2725 * 2618 2726 * @since 3.5.0 … … 2622 2730 */ 2623 2731 function wp_send_json( $response ) { 2624 2732 @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); 2625 echo json_encode( $response );2733 echo wp_json_encode( $response ); 2626 2734 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) 2627 2735 wp_die(); 2628 2736 else -
src/wp-includes/media.php
1398 1398 } 1399 1399 ?></ol> 1400 1400 </noscript> 1401 <script type="application/json" class="wp-playlist-script"><?php echo json_encode( $data ) ?></script>1401 <script type="application/json" class="wp-playlist-script"><?php echo wp_json_encode( $data ) ?></script> 1402 1402 </div> 1403 1403 <?php 1404 1404 return ob_get_clean(); … … 2582 2582 'limitExceeded' => is_multisite() && ! is_upload_space_available() 2583 2583 ); 2584 2584 2585 $script = 'var _wpPluploadSettings = ' . json_encode( $settings ) . ';';2585 $script = 'var _wpPluploadSettings = ' . wp_json_encode( $settings ) . ';'; 2586 2586 2587 2587 if ( $data ) 2588 2588 $script = "$data\n$script"; -
src/wp-includes/theme.php
1935 1935 ), 1936 1936 ); 1937 1937 1938 $script = 'var _wpCustomizeLoaderSettings = ' . json_encode( $settings ) . ';';1938 $script = 'var _wpCustomizeLoaderSettings = ' . wp_json_encode( $settings ) . ';'; 1939 1939 1940 1940 $data = $wp_scripts->get_data( 'customize-loader', 'data' ); 1941 1941 if ( $data ) -
src/wp-includes/update.php
94 94 ); 95 95 96 96 $post_body = array( 97 'translations' => json_encode( $translations ),97 'translations' => wp_json_encode( $translations ), 98 98 ); 99 99 100 100 if ( is_array( $extra_stats ) ) … … 274 274 $options = array( 275 275 'timeout' => $timeout, 276 276 'body' => array( 277 'plugins' => json_encode( $to_send ),278 'translations' => json_encode( $translations ),279 'locale' => json_encode( $locales ),280 'all' => json_encode( true ),277 'plugins' => wp_json_encode( $to_send ), 278 'translations' => wp_json_encode( $translations ), 279 'locale' => wp_json_encode( $locales ), 280 'all' => wp_json_encode( true ), 281 281 ), 282 282 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 283 283 ); 284 284 285 285 if ( $extra_stats ) { 286 $options['body']['update_stats'] = json_encode( $extra_stats );286 $options['body']['update_stats'] = wp_json_encode( $extra_stats ); 287 287 } 288 288 289 289 $url = $http_url = 'http://api.wordpress.org/plugins/update-check/1.1/'; … … 437 437 $options = array( 438 438 'timeout' => $timeout, 439 439 'body' => array( 440 'themes' => json_encode( $request ),441 'translations' => json_encode( $translations ),442 'locale' => json_encode( $locales ),440 'themes' => wp_json_encode( $request ), 441 'translations' => wp_json_encode( $translations ), 442 'locale' => wp_json_encode( $locales ), 443 443 ), 444 444 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 445 445 ); 446 446 447 447 if ( $extra_stats ) { 448 $options['body']['update_stats'] = json_encode( $extra_stats );448 $options['body']['update_stats'] = wp_json_encode( $extra_stats ); 449 449 } 450 450 451 451 $url = $http_url = 'http://api.wordpress.org/themes/update-check/1.1/'; -
tests/phpunit/tests/functions.php
529 529 $this->assertCount( 8, $urls ); 530 530 $this->assertEquals( array_slice( $original_urls, 0, 8 ), $urls ); 531 531 } 532 533 /** 534 * @ticket 28786 535 */ 536 function test_wp_json_encode() { 537 $this->assertEquals( wp_json_encode( 'a' ), '"a"' ); 538 $this->assertEquals( wp_json_encode( '这' ), '"\u8fd9"' ); 539 540 $old_charsets = $charsets = mb_detect_order(); 541 if ( ! in_array( 'EUC-JP', $charsets ) ) { 542 $charsets[] = 'EUC-JP'; 543 mb_detect_order( $charsets ); 544 } 545 546 $eucjp = mb_convert_encoding( 'aあb', 'EUC-JP', 'UTF-8' ); 547 $utf8 = mb_convert_encoding( $eucjp, 'UTF-8', 'EUC-JP' ); 548 549 $this->assertEquals( 'aあb', $utf8 ); 550 551 $this->assertEquals( wp_json_encode( $eucjp ), '"a\u3042b"' ); 552 553 $this->assertEquals( wp_json_encode( array( 'a' ) ), '["a"]' ); 554 555 $object = new stdClass; 556 $object->a = 'b'; 557 $this->assertEquals( wp_json_encode( $object ), '{"a":"b"}' ); 558 559 mb_detect_order( $old_charsets ); 560 } 561 562 /** 563 * @ticket 28786 564 */ 565 function test_wp_json_encode_depth() { 566 $data = array( array( array( 1, 2, 3 ) ) ); 567 $json = wp_json_encode( $data, 0, 1 ); 568 $this->assertFalse( $json ); 569 570 $data = array( 'あ', array( array( 1, 2, 3 ) ) ); 571 $json = wp_json_encode( $data, 0, 1 ); 572 $this->assertFalse( $json ); 573 } 532 574 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)