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.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @nazmulasif.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

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.

@nazmulasif

Copy link
Copy Markdown

Test Report
Patch tested: #12103

Environment

  • WordPress: 7.1-beta4-20260730.062011
  • Subdirectory: No
  • PHP: 8.5.8 (cli)
  • Server: PHP.wasm (Emscripten 4.0.19 wasm32)
  • Database: WP_MySQL_On_SQLite (Server: 8.0.38 / Client: 3.51.0)
  • Browser: Chrome 150.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.5
  • MU Plugins: None activated
  • Plugins:
    • Classic Editor 1.7.0
    • Test Reports 1.3.0

Steps taken

  1. Opened WordPress Playground PR preview for PR 65417 Editor: Recognize uppercase URL schemes in link validation. #12103 (Trac #65417) with the Classic Editor active.
  2. Navigated to Posts > Add New and created a Classic Editor instance.
  3. Added sample text, selected it, and clicked the Insert/Edit Link icon in the toolbar.
  4. Clicked the Link Options gear icon (⚙️) to open the full wpLink modal dialog.
  5. In the URL field, entered a URL with an uppercase protocol (https://example.com/ and http://example.com/).
  6. Moved focus away from the input field (triggered blur event / wpLink.correctURL()) and submitted the link dialog.
  7. Also verified directly in the browser developer console by targeting the modal input DOM element:
    jQuery('#wp-link-url').val('https://example.com/');
    wpLink.correctURL();
    console.log(jQuery('#wp-link-url').val());
    // Result: "https://example.com/"
  8. Confirmed that the URL protocol is preserved as entered without prepending http://.
  • ✅ Patch is solving the problem

Expected result
URLs containing uppercase or mixed-case protocols (e.g. https://example.com/ or http://example.com/) should be recognized as already having a scheme and should NOT have http:// prepended to create broken double-protocol URLs (http://https/://example.com).

Additional Notes
Tested and verified pull request #12103 for Trac #65417.

Screenshots/Screencast with results
Attached: showing manual test verification in post editor

Support Content
Trac Ticket: https://core.trac.wordpress.org/ticket/65417

WordPress-Playground.mp4

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.

4 participants