[wp-trac] [WordPress Trac] #41488: Customize: uncaught JS error with namespaced nav menu fallbacks
WordPress Trac
noreply at wordpress.org
Mon Jul 31 21:16:09 UTC 2017
#41488: Customize: uncaught JS error with namespaced nav menu fallbacks
--------------------------+------------------
Reporter: dlh | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: 4.9
Component: Customize | Version: 4.3
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
--------------------------+------------------
Comment (by westonruter):
@dlh yeah, I can see that the JSON is getting corrupted. To illustrate
that the problem resides in slashing, try adding this patch:
{{{#!diff
--- src/wp-includes/class-wp-customize-nav-menus.php
+++ src/wp-includes/class-wp-customize-nav-menus.php
@@ -1271,7 +1271,7 @@ final class WP_Customize_Nav_Menus {
if ( isset(
$args->customize_preview_nav_menus_args['can_partial_refresh'] ) &&
$args->customize_preview_nav_menus_args['can_partial_refresh'] ) {
$attributes = sprintf( ' data-customize-partial-
id="%s"', esc_attr( 'nav_menu_instance[' .
$args->customize_preview_nav_menus_args['args_hmac'] . ']' ) );
$attributes .= ' data-customize-partial-
type="nav_menu_instance"';
- $attributes .= sprintf( ' data-customize-partial-
placement-context="%s"', esc_attr( wp_json_encode(
$args->customize_preview_nav_menus_args ) ) );
+ $attributes .= sprintf( ' data-customize-partial-
placement-context="%s"', wp_slash( esc_attr( wp_json_encode(
$args->customize_preview_nav_menus_args ) ) ) );
$nav_menu_content = preg_replace( '#^(<\w+)#', '$1
' . $attributes, $nav_menu_content, 1 );
}
return $nav_menu_content;
}}}
You'll see that by wrapping the escaped attribute in `wp_slash`, it
prevents the slashes from getting dropped. Somewhere somehow there is
`wp_unslash()` or `stripslashes()` that is causing the JSON string
`"\\WordPress\\my_callback"` to become the invalid
`"\WordPress\my_callback"`.
This is the underlying issue that needs to be fixed.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41488#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list