Skip to content

65417 Editor: Recognize uppercase URL schemes in link validation. - #12103

Open
nimesh-xecurify wants to merge 4 commits into
WordPress:trunkfrom
nimesh-xecurify:65417-editor-js-fix
Open

65417 Editor: Recognize uppercase URL schemes in link validation.#12103
nimesh-xecurify wants to merge 4 commits into
WordPress:trunkfrom
nimesh-xecurify:65417-editor-js-fix

Conversation

@nimesh-xecurify

Copy link
Copy Markdown

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.

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

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.
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props nimeshatxecurify, wildworks.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI review requested due to automatic review settings July 28, 2026 07:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 wplink script 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.

Comment thread src/js/_enqueues/lib/link.js Outdated
Comment on lines +94 to +98
@@ -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 ) ) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI review requested due to automatic review settings July 30, 2026 06:15
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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 30, 2026 06:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants