65417 Editor: Recognize uppercase URL schemes in link validation. - #12103
65417 Editor: Recognize uppercase URL schemes in link validation.#12103nimesh-xecurify wants to merge 4 commits into
Conversation
Updates the regex used in the link dialog to support schemes with uppercase letters. This prevents the editor from prepending `http://` to URLs like `HTTPS://` or `Http://`, which are commonly produced by mobile keyboards. Includes new QUnit tests to verify correct handling of uppercase, mixed-case, fragment, and root-relative URLs.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
Pull request overview
This PR updates the link-correction logic used by the editor/link dialog so that URLs with uppercase or mixed-case schemes (e.g. HTTPS://, Http://) are recognized as already having a scheme and are not modified by automatically prepending http://. It also adds QUnit coverage around the updated behavior.
Changes:
- Expand the “has a scheme” regex in both the core link dialog code and the TinyMCE wplink plugin to recognize uppercase scheme letters.
- Add new QUnit tests covering lowercase, uppercase, mixed-case schemes, plus fragment and root-relative URLs.
- Load the
wplinkscript and provide minimal fixture/L10n setup for the new QUnit tests.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/qunit/wp-includes/js/wplink.js | Adds QUnit tests for wpLink.correctURL() handling of schemes/fragments/root-relative URLs. |
| tests/qunit/index.html | Loads wplink.js in the QUnit runner and adds a minimal fixture input + wpLinkL10n stub. |
| src/js/_enqueues/vendor/tinymce/plugins/wplink/plugin.js | Updates scheme-detection regex to accept uppercase letters in TinyMCE’s wplink flow. |
| src/js/_enqueues/lib/link.js | Updates scheme-detection regex to accept uppercase letters in wpLink.correctURL(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -95,7 +95,7 @@ | |||
| correctURL: function () { | |||
| var url = inputs.url.val().trim(); | |||
|
|
|||
| if ( url && correctedURL !== url && ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( url ) ) { | |||
| if ( url && correctedURL !== url && ! /^(?:[a-zA-Z]+:|#|\?|\.|\/)/.test( url ) ) { | |||
There was a problem hiding this comment.
Good catch — addressed in 1960237.
The scheme pattern is now [a-zA-Z][a-zA-Z0-9+-]*:, so chrome-extension:// and web+demo:// are recognized, and the inline comment above correctURL() now describes what the regex actually checks.
One deliberate deviation from RFC 3986: the . that the spec permits in a scheme is left out. Including it would make example.com:8080 parse as the scheme example.com, so a bare host and port would no longer get http:// prepended — a regression against current behaviour. Bare host:port input seems more likely in the link dialog than a scheme containing a dot.
Added QUnit coverage for all three cases: hyphenated scheme, +/digit scheme, and example.com:8080/path still being corrected.
Extends the scheme-detection regex beyond letters to also allow digits, `+` and `-` after the first letter, so URLs such as `chrome-extension://` and `web+demo://` are recognized as already having a scheme. The `.` allowed by RFC 3986 is deliberately excluded so that a bare host and port such as `example.com:8080` is still corrected to `http://example.com:8080` rather than being read as a scheme. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Updates the regex used in the link dialog to support schemes with uppercase letters. This prevents the editor from prepending
http://to URLs likeHTTPS://orHttp://, which are commonly produced by mobile keyboards.Includes new QUnit tests to verify correct handling of uppercase, mixed-case, fragment, and root-relative URLs.
Trac ticket: https://core.trac.wordpress.org/ticket/65417
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Sonnet 4.6