TinyMCE, inline link:

- Remove proxying through WordPress to test if an URL exists.
- Fix and enhance the regex that tests if the URL is well formed.

Fixes #36638.

git-svn-id: https://develop.svn.wordpress.org/trunk@38159 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz
2016-07-26 23:23:21 +00:00
parent 63980b7cf3
commit d16d808d8b
4 changed files with 9 additions and 88 deletions
@@ -93,8 +93,9 @@
var doingUndoRedo;
var doingUndoRedoTimer;
var $ = window.jQuery;
var urlErrors = {};
var emailRegex = /^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}$/i;
var urlRegex1 = /^https?:\/\/([^\s/?.#-][^\s\/?.#]*\.?)+(\/[^\s"]*)?$/i;
var urlRegex2 = /^https?:\/\/[^\/]+\.[^\/]+($|\/)/i;
var speak = ( typeof window.wp !== 'undefined' && window.wp.a11y && window.wp.a11y.speak ) ? window.wp.a11y.speak : function() {};
var hasLinkError = false;
@@ -150,16 +151,6 @@
});
}
function setLinkError( $link ) {
hasLinkError = true;
$link.attr( 'data-wplink-url-error', 'true' );
speak( editor.translate( 'Warning: the link has been inserted but the destination cannot be reached.' ), 'assertive' );
if ( toolbar && toolbar.visible() ) {
toolbar.$el.find( '.wp-link-preview a' ).addClass( 'wplink-url-error' );
}
}
function checkLink( node ) {
var $link = editor.$( node );
var href = $link.attr( 'href' );
@@ -170,34 +161,13 @@
hasLinkError = false;
if ( /^http/i.test( href ) && ! /^https?:\/\/[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}(\/|$)/i.test( href ) ) {
urlErrors[href] = true;
}
if ( urlErrors.hasOwnProperty( href ) ) {
setLinkError( $link );
return;
if ( /^http/i.test( href ) && ( ! urlRegex1.test( href ) || ! urlRegex2.test( href ) ) ) {
hasLinkError = true;
$link.attr( 'data-wplink-url-error', 'true' );
speak( editor.translate( 'Warning: the link has been inserted but may have errors. Please test it.' ), 'assertive' );
} else {
$link.removeAttr( 'data-wplink-url-error' );
}
$.post(
window.ajaxurl, {
action: 'test_url',
nonce: $( '#_wplink_urltest_nonce' ).val(),
href: href
},
'json'
).done( function( response ) {
if ( response.success ) {
return;
}
if ( response.data && response.data.httpError ) {
urlErrors[href] = true;
setLinkError( $link );
}
});
}
editor.on( 'preinit', function() {