Changeset 42153
- Timestamp:
- 11/10/2017 11:40:41 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/customize-nav-menus.js
r42034 r42153 538 538 itemName = $( '#custom-menu-item-name' ), 539 539 itemUrl = $( '#custom-menu-item-url' ), 540 urlRegex, 541 urlValue; 540 urlRegex; 542 541 543 542 if ( ! this.currentMenuControl ) { … … 546 545 547 546 /* 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. 552 557 */ 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 556 560 if ( '' === itemName.val() ) { 557 561 itemName.addClass( 'invalid' ); 558 562 return; 559 } else if ( '' === urlValue || 'http://' === urlValue || ! ( '/' === urlValue[0] || urlRegex.test( urlValue) ) ) {563 } else if ( ! urlRegex.test( itemUrl.val() ) ) { 560 564 itemUrl.addClass( 'invalid' ); 561 565 return; … … 564 568 menuItem = { 565 569 'title': itemName.val(), 566 'url': urlValue,570 'url': itemUrl.val(), 567 571 'type': 'custom', 568 572 'type_label': api.Menus.data.l10n.custom_label,
Note: See TracChangeset
for help on using the changeset viewer.