Make WordPress Core


Ignore:
Timestamp:
08/02/2017 05:10:05 AM (8 years ago)
Author:
westonruter
Message:

Customize: For selective refresh of nav menus, prevent preg_replace() from dropping backslashes in JSON replaced into the data-customize-partial-placement-context HTML attribute.

Props dlh, westonruter.
Fixes #41488.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/nav-menus.php

    r39924 r41204  
    862862     * Test the filter_wp_nav_menu method.
    863863     *
    864      * @see WP_Customize_Nav_Menus::filter_wp_nav_menu()
     864     * @covers WP_Customize_Nav_Menus::filter_wp_nav_menu()
     865     * @covers WP_Customize_Nav_Menus::filter_wp_nav_menu_args()
    865866     */
    866867    function test_filter_wp_nav_menu() {
     
    868869        $menus = new WP_Customize_Nav_Menus( $this->wp_customize );
    869870
    870         $args = $menus->filter_wp_nav_menu_args( array(
     871        $original_args = array(
    871872            'echo'        => true,
    872873            'menu'        => wp_create_nav_menu( 'Foo' ),
     
    874875            'walker'      => '',
    875876            'items_wrap'  => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    876         ) );
     877        );
     878
     879        // Add global namespace prefix to check #41488.
     880        if ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
     881            $original_args['fallback_cb'] = '\\' . $original_args['fallback_cb'];
     882        }
     883
     884        $args = $menus->filter_wp_nav_menu_args( $original_args );
    877885
    878886        ob_start();
     
    884892        $this->assertContains( sprintf( ' data-customize-partial-id="nav_menu_instance[%s]"', $args['customize_preview_nav_menus_args']['args_hmac'] ), $result );
    885893        $this->assertContains( ' data-customize-partial-type="nav_menu_instance"', $result );
    886         $this->assertContains( ' data-customize-partial-placement-context="', $result );
     894        $this->assertTrue( (bool) preg_match( '/data-customize-partial-placement-context="(.+?)"/', $result, $matches ) );
     895        $context = json_decode( html_entity_decode( $matches[1] ), true );
     896        $this->assertEquals( $original_args, wp_array_slice_assoc( $context, array_keys( $original_args ) ) ); // Because assertArraySubset is not available in PHP 5.2.
     897        $this->assertTrue( $context['can_partial_refresh'] );
    887898    }
    888899
Note: See TracChangeset for help on using the changeset viewer.