Make WordPress Core

Changeset 42153


Ignore:
Timestamp:
11/10/2017 11:40:41 PM (7 years ago)
Author:
westonruter
Message:

Customize: Restore ability to add Custom Link nav menu items for jump links and other URLs that were previously allowed.

Simplify regular expression for checking URL validity to just do basic checks to confirm the value looks like a URL. Leave the complete validation to the server-side logic in WP_Customize_Nav_Menu_Item_Setting::sanitize() to avoid having to maintain two separate codebases for validating URLs.

Props westonruter, SergeyBiryukov for testing.
Amends [41697].
See #32816.
Fixes #42506 for trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/customize-nav-menus.js

    r42034 r42153  
    538538                itemName = $( '#custom-menu-item-name' ),
    539539                itemUrl = $( '#custom-menu-item-url' ),
    540                 urlRegex,
    541                 urlValue;
     540                urlRegex;
    542541
    543542            if ( ! this.currentMenuControl ) {
     
    546545
    547546            /*
    548              * Copyright (c) 2010-2013 Diego Perini, MIT licensed
    549              * https://gist.github.com/dperini/729294
    550              * see also https://mathiasbynens.be/demo/url-regex
    551              * modified to allow protocol-relative URLs
     547             * Allow URLs including:
     548             * - http://example.com/
     549             * - //example.com
     550             * - /directory/
     551             * - ?query-param
     552             * - #target
     553             * - mailto:foo@example.com
     554             *
     555             * Any further validation will be handled on the server when the setting is attempted to be saved,
     556             * so this pattern does not need to be complete.
    552557             */
    553             urlRegex = /^(?:(?:(?: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;
    554 
    555             urlValue = itemUrl.val();
     558            urlRegex = /^((\w+:)?\/\/\w.*|\w+:(?!\/\/$)|\/|\?|#)/;
     559
    556560            if ( '' === itemName.val() ) {
    557561                itemName.addClass( 'invalid' );
    558562                return;
    559             } else if ( '' === urlValue || 'http://' === urlValue || ! ( '/' === urlValue[0] || urlRegex.test( urlValue ) ) ) {
     563            } else if ( ! urlRegex.test( itemUrl.val() ) ) {
    560564                itemUrl.addClass( 'invalid' );
    561565                return;
     
    564568            menuItem = {
    565569                'title': itemName.val(),
    566                 'url': urlValue,
     570                'url': itemUrl.val(),
    567571                'type': 'custom',
    568572                'type_label': api.Menus.data.l10n.custom_label,
Note: See TracChangeset for help on using the changeset viewer.