WordPress.org

Make WordPress Core

Ticket #32816: rmarks-32816-2.diff

File rmarks-32816-2.diff, 1.1 KB (added by RMarks, 3 years ago)

Updated the sanitization test since url defaults to an empty string

  • src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php

    diff --git src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php
    index 11b5cd6..c970f2f 100644
    class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting { 
    722722                $menu_item_value['attr_title'] = wp_unslash( apply_filters( 'excerpt_save_pre', wp_slash( $menu_item_value['attr_title'] ) ) );
    723723                $menu_item_value['description'] = wp_unslash( apply_filters( 'content_save_pre', wp_slash( $menu_item_value['description'] ) ) );
    724724
    725                 $menu_item_value['url'] = esc_url_raw( $menu_item_value['url'] );
     725                if( '' !== $menu_item_value['url'] ) {
     726                        $menu_item_value['url'] = esc_url_raw( $menu_item_value['url'] );
     727                        if ( '' === $menu_item_value['url'] ) {
     728                                return new WP_Error( 'invalid_nav_menu_url', __( 'Invalid URL.' ) ); // Fail sanitization if URL is invalid.
     729                        }
     730                }
     731
    726732                if ( 'publish' !== $menu_item_value['status'] ) {
    727733                        $menu_item_value['status'] = 'draft';
    728734                }