diff --git a/src/js/_enqueues/lib/link.js b/src/js/_enqueues/lib/link.js index a2500a9069648..6e4b82b3c0929 100644 --- a/src/js/_enqueues/lib/link.js +++ b/src/js/_enqueues/lib/link.js @@ -91,11 +91,16 @@ inputs.url.on( 'blur', wpLink.correctURL ); }, - // If URL wasn't corrected last time and doesn't start with http:, https:, ? # or /, prepend http://. + /* + * If the URL wasn't corrected last time and doesn't start with a scheme + * (a letter followed by letters, digits, `+` or `-`, then a colon, matching + * RFC 3986 minus the dot so that `example.com:8080` is still corrected), + * `#`, `?`, `.` or `/`, prepend http://. + */ correctURL: function () { var url = inputs.url.val().trim(); - if ( url && correctedURL !== url && ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( url ) ) { + if ( url && correctedURL !== url && ! /^(?:[a-zA-Z][a-zA-Z0-9+-]*:|#|\?|\.|\/)/.test( url ) ) { inputs.url.val( 'http://' + url ); correctedURL = url; } diff --git a/src/js/_enqueues/vendor/tinymce/plugins/wplink/plugin.js b/src/js/_enqueues/vendor/tinymce/plugins/wplink/plugin.js index 76781894171e8..8168f011cf802 100644 --- a/src/js/_enqueues/vendor/tinymce/plugins/wplink/plugin.js +++ b/src/js/_enqueues/vendor/tinymce/plugins/wplink/plugin.js @@ -264,7 +264,7 @@ return; } - if ( ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( href ) && ! emailRegex.test( href ) ) { + if ( ! /^(?:[a-zA-Z][a-zA-Z0-9+-]*:|#|\?|\.|\/)/.test( href ) && ! emailRegex.test( href ) ) { href = 'http://' + href; } diff --git a/tests/qunit/index.html b/tests/qunit/index.html index a6b6177014586..f9905bc924579 100644 --- a/tests/qunit/index.html +++ b/tests/qunit/index.html @@ -76,6 +76,7 @@
+ @@ -87,6 +88,8 @@
+ + @@ -167,6 +170,7 @@ +