WordPress.org

Make WordPress Core

Ticket #32816: 32816-ataylor-js-validation.diff

File 32816-ataylor-js-validation.diff, 2.3 KB (added by andrew.taylor, 3 years ago)

Here is a diff with @RMarks PHP validation adding JavaScript validation.

  • src/wp-admin/js/customize-nav-menus.js

    diff --git a/src/wp-admin/js/customize-nav-menus.js b/src/wp-admin/js/customize-nav-menus.js
    index a8e314d..096a31b 100644
    a b  
    545545                        if ( '' === itemName.val() ) {
    546546                                itemName.addClass( 'invalid' );
    547547                                return;
    548                         } else if ('' === itemUrl.val() ||
    549                                 'http://' === itemUrl.val() ||
    550                                 // Copyright (c) 2010-2013 Diego Perini, MIT licensed
    551                                 // https://gist.github.com/dperini/729294
    552                                 // see also https://mathiasbynens.be/demo/url-regex
    553                                 // modified to allow protocol-relative URLs
    554                                 /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(value)
    555                         ) {
    556                                 itemUrl.addClass('invalid');
     548                        } else if ( '' === itemUrl.val() || 'http://' === itemUrl.val() ) {
     549                                itemUrl.addClass( 'invalid' );
    557550                                return;
    558551                        }
    559552
  • src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php

    diff --git a/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php b/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php
    index efa63f6..11b5cd6 100644
    a b 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                 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                 }
     725                $menu_item_value['url'] = esc_url_raw( $menu_item_value['url'] );
    731726                if ( 'publish' !== $menu_item_value['status'] ) {
    732727                        $menu_item_value['status'] = 'draft';
    733728                }