Make WordPress Core

Ticket #48011: 48011-3.diff

File 48011-3.diff, 2.0 KB (added by birgire, 5 years ago)
  • src/wp-includes/nav-menu.php

    diff --git src/wp-includes/nav-menu.php src/wp-includes/nav-menu.php
    index 3493961..4f25dea 100644
    function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item 
    491491                        }
    492492                }
    493493
    494                 if ( $args['menu-item-title'] == $original_title ) {
     494                if ( wp_unslash( $args['menu-item-title'] ) == wp_specialchars_decode( $original_title ) ) {
    495495                        $args['menu-item-title'] = '';
    496496                }
    497497
  • tests/phpunit/tests/post/nav-menu.php

    diff --git tests/phpunit/tests/post/nav-menu.php tests/phpunit/tests/post/nav-menu.php
    index 0001bbc..d9ab9c7 100644
    class Test_Nav_Menus extends WP_UnitTestCase { 
    956956                );
    957957        }
    958958
     959        /**
     960         * Tests `wp_update_nav_menu_item()` with special characters in a category name.
     961         *
     962         * When inserting a category as a nav item, the `$args['menu-item-title']` should
     963         * always be empty as it should get the title from the category object itself.
     964         *
     965         * @ticket 48011
     966         */
     967        function test_wp_update_nav_menu_item_with_special_character_in_categories() {
     968
     969                $category_name = 'Test Cat - \"Pre-Slashed\" Cat Name & >';
     970
     971                $cat = self::factory()->category->create_and_get(
     972                        array(
     973                                'name' => $category_name,
     974                        )
     975                );
     976
     977                add_action( 'wp_update_nav_menu_item', array( $this, '_callback_wp_update_nav_menu_item_48011' ), 10, 3 );
     978
     979                $id = wp_update_nav_menu_item(
     980                        $this->menu_id,
     981                        0,
     982                        array(
     983                                'menu-item-type'      => 'taxonomy',
     984                                'menu-item-object'    => 'category',
     985                                'menu-item-object-id' => $cat->term_id,
     986                                'menu-item-status'    => 'publish',
     987                                'menu-item-title'     => $category_name,    // Interesting enough, if we use `$cat->name` we won't be able to
     988                                                                                                                        // replicate the bug because it's in htmlentities form.
     989                        )
     990                );
     991        }
     992
     993        /**
     994         * Callback for the `wp_update_nav_menu_item` action.
     995         *
     996         * @since 5.4.0
     997         */
     998        function _callback_wp_update_nav_menu_item_48011( $menu_id, $menu_item_db_id, $args ) {
     999                $this->assertEmpty( $args['menu-item-title'] );
     1000        }
    9591001}