Skip to content

URL: Make scheme detection in prependHTTP more semantic - #85515

Open
t-hamano wants to merge 4 commits into
trunkfrom
fix/prepend-http-scheme-detection
Open

t-hamano wants to merge 4 commits into
trunkfrom
fix/prepend-http-scheme-detection

Conversation

@t-hamano

@t-hamano t-hamano commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What?

I noticed this while reviewing WordPress/wordpress-develop#12103.

Updates the regular expression used by prependHTTP and prependHTTPS to detect whether a URL already has a scheme.

Why?

prependHTTP and prependHTTPS appear to have been created based on correctURL in the classic editor (see #5917). However, a bug was reported where correctURL prepends http:// even when it shouldn't. This PR updates the regular expression used by prependHTTP and prependHTTPS to a more semantic one, following the implementation being proposed in core.

How?

Previously, only a scheme made up of letters followed by a colon was recognized. As a result, a URL whose scheme contains digits, + or -, such as chrome-extension:// or web+demo2://, got http:// prepended.

This PR additionally recognizes a scheme that starts with a letter and contains letters, digits, + or -, but only when it is followed by //. Requiring // keeps the existing behavior for a bare host and port such as my-site:8080/path or site1:80, which still get http:// prepended. A scheme of letters only is still recognized with just a colon, as before.

Input Before After
chrome-extension://abcdef/options.html http://chrome-extension://abcdef/options.html Unchanged
web+demo2://wordpress.org http://web+demo2://wordpress.org Unchanged
HTTPS://wordpress.org, Http://wordpress.org, mailto:foo@wordpress.org Unchanged Unchanged
localhost:8888 Unchanged Unchanged
my-site:8080/path, site1:80, wordpress.org:8080/path http:// prepended http:// prepended

Testing Instructions

  1. Open a post or page.
  2. Insert a Paragraph block and type some text.
  3. Select a word and click the Link button in the block toolbar.
  4. Enter chrome-extension://abcdef/options.html and press Enter.
  5. Check the link URL:
    • Before: It becomes https://chrome-extension://abcdef/options.html.
    • After: It is kept as chrome-extension://abcdef/options.html.
  6. Repeat with my-site:8080/path and confirm that https:// is prepended, as on trunk.
  7. Repeat with HTTPS://wordpress.org and confirm that it is kept as is, as on trunk.

Testing Instructions for Keyboard

Same as above. Use Cmd/Ctrl + K to open the link UI.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Used for: Implementing the change, updating the unit tests, and drafting this description. Reviewed by me.

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X3oDSXQzXqDWGmZ2ER5y1U
@t-hamano t-hamano self-assigned this Oct 25, 2026
@github-actions github-actions Bot added the [Package] Url /packages/url label Oct 25, 2026
@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: t-hamano <wildworks@git.wordpress.org>

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +11 B (0%)

Total Size: 8.66 MB

📦 View Changed
Filename Size Change
build/scripts/url/index.min.js 3.55 kB +11 B (+0.31%)

032fa07 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric e415974 trunk % Change
timeToFirstByte 43.25 ms +4.62% -5.09% 42.35 ms +10.63% -3.78% 2.13%
largestContentfulPaint 72 ms +5.56% -5.56% 66 ms +6.06% -3.03% 9.09%
lcpMinusTtfb 28.15 ms +4.62% -12.97% 22.75 ms +4.84% -5.27% 23.74%
wpBeforeTemplate 22.35 ms +8.28% -2.33% 21.88 ms +11.24% -1.55% 2.15%
wpTemplate 17.3 ms +5.03% -6.24% 16.99 ms +2.3% -5.83% 1.82%
wpTotal 39.91 ms +5.66% -5.16% 39 ms +11.18% -3.85% 2.33%
wpMemoryUsage 7.75 MB +0% -0% 7.71 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric e415974 trunk % Change
timeToFirstByte 35.05 ms +9.84% -2.14% 34.7 ms +8.93% -2.74% 1.01%
largestContentfulPaint 64 ms +6.25% -0% 60 ms +6.67% -0% 6.67%
lcpMinusTtfb 29.3 ms +2.73% -1.88% 26.4 ms +1.89% -2.46% 10.98%
wpBeforeTemplate 19.38 ms +7.89% -2.12% 19.06 ms +9.08% -1.63% 1.68%
wpTemplate 12.92 ms +3.87% -2.79% 12.74 ms +3.22% -2.51% 1.41%
wpTotal 32.39 ms +9.26% -1.88% 32.03 ms +9.18% -2.81% 1.12%
wpMemoryUsage 6.44 MB +0% -0% 6.40 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric e415974 trunk % Change
mediaProcessingJpeg 324.22 ms +1.33% -0.56% 322.91 ms +1% -0.59% 0.41%
mediaProcessingAvif 4866.36 ms +0.23% -0.06% 4842.25 ms +0.2% -0.31% 0.5%
mediaProcessingJpegToAvif 3390.52 ms +0.1% -0.17% 3393.13 ms +0.1% -0.41% -0.08%

media-upload

Metric e415974 trunk % Change
jpegUploadProcessing 1473.56 ms +0.93% -1.9% 1450.42 ms +0.58% -0.48% 1.6%
pngUploadProcessing 233.85 ms +2.54% -3.49% 235.49 ms +8.9% -7.79% -0.7%
largeJpegUploadProcessing 1439.08 ms +0.99% -0.9% 1440.29 ms +0.34% -0.59% -0.08%
multipleImageUploadProcessing 1513.54 ms +2.29% -2.26% 1486.11 ms +1.39% -0.29% 1.85%

post-editor

Metric e415974 trunk % Change
serverResponse 486.13 ms +0.39% -11.39% 472.56 ms +3.28% -6.7% 2.87%
firstPaint 430.76 ms +6.86% -8.03% 403.95 ms +12.58% -1.38% 6.64%
domContentLoaded 809.07 ms +5.54% -1.71% 814.26 ms +1.01% -1.52% -0.64%
loaded 810.05 ms +5.56% -1.65% 815.5 ms +1% -1.51% -0.67%
firstContentfulPaint 465.36 ms +8.82% -3.8% 457.42 ms +0.58% -0.58% 1.74%
firstBlock 2175.25 ms +3.83% -1.91% 2165.91 ms +0.98% -0.27% 0.43%
type 16.33 ms +9.49% -6.25% 17.56 ms +5.58% -8.49% -7%
typeWithoutInspector 17.38 ms +5.58% -19.74% 16.89 ms +5.57% -6.22% 2.9%
typeWithTopToolbar 23.27 ms +2.41% -4.17% 21.68 ms +10.33% -4.43% 7.33%
typeContainer 8.2 ms +10.49% -8.05% 7.81 ms +4.87% -8.45% 4.99%
focus 122.03 ms +4.81% -3.67% 114.57 ms +4.51% -6.55% 6.51%
firstFocus 279.36 ms +0% -0% 266.7 ms +0% -0% 4.75%
selectAll 404.35 ms +2.91% -0.58% 422.71 ms +0.25% -1.24% -4.34%
undo 29.36 ms +8.38% -5.04% 27.24 ms +8.81% -3.56% 7.78%
listViewOpen 83.74 ms +2.81% -8.9% 73.93 ms +9.48% -8.48% 13.27%
inserterOpen 40.26 ms +7.2% -5.14% 41.25 ms +4.34% -6.84% -2.4%
inserterHover 11.95 ms +5.44% -12.47% 10.83 ms +11.73% -9.05% 10.34%
inserterSearch 7.47 ms +15.66% -3.75% 8.32 ms +8.77% -7.57% -10.22%
loadPatterns 644.69 ms +1.64% -4.79% 622.98 ms +3.83% -2.28% 3.48%
wpTotal 476.32 ms +0.39% -11.55% 462.97 ms +3.3% -6.92% 2.88%
wpMemoryUsage 14.81 MB +0% -0% 14.77 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric e415974 trunk % Change
serverResponse 252.1 ms +1.28% -0.82% 259.64 ms +2.2% -8.09% -2.9%
firstPaint 301.79 ms +4.72% -14.14% 307.21 ms +5.89% -6.43% -1.76%
domContentLoaded 528.9 ms +0.72% -1% 541.48 ms +3.03% -0.64% -2.32%
loaded 529.7 ms +0.72% -1.01% 542.18 ms +3.06% -0.63% -2.3%
firstContentfulPaint 304.85 ms +3.66% -1.35% 308.96 ms +6.46% -0.91% -1.33%
firstBlock 1630.93 ms +0.79% -1.94% 1671.01 ms +1.3% -1.16% -2.4%
type 13.7 ms +1.68% -17.88% 19.24 ms +12.94% -29.99% -28.79%
navigate 78.97 ms +7.38% -5.41% 69.66 ms +18.98% -4.52% 13.36%
loadPatterns 996.06 ms +7.22% -13.16% 993.92 ms +1.11% -9.97% 0.22%
loadPages 913.14 ms +2.12% -1.22% 937.72 ms +3.63% -3.02% -2.62%
wpTotal 245.82 ms +1.33% -0.79% 253.11 ms +2.22% -8.33% -2.88%
wpMemoryUsage 12.82 MB +0% -0% 12.79 MB +0% -0% 0.25%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

032fa07 Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in /test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

  Object {
    "attributeKey": "content",
    "blockIndex": 0,
    "content": "abcdef",
-   "endOffset": 3,
-   "offset": 3,
+   "endOffset": 6,
+   "offset": 6,
  }

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts:363:5
should reset a named font size using input field in /test/e2e/specs/editor/various/font-size-picker.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:paragraph {"fontSize":"small"} -->
+ <!-- wp:paragraph {"fontSize":"tiny"} -->
- <p class="has-small-font-size">Paragraph with font size reset using input field</p>
+ <p class="has-tiny-font-size">Paragraph with font size reset using input field</p>
  <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/font-size-picker.spec.js:216:6
should select synced pattern in /test/e2e/specs/editor/various/writing-flow.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]') with timeout 5000ms
  - waiting for locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
    14 × locator resolved to <div tabindex="0" role="document" draggable="true" data-title="Pattern" data-type="core/block" data-is-drop-zone="true" aria-label="Block: Pattern" id="block-ec31c176-0968-4e41-9978-34b80fe0a8cf" data-block="ec31c176-0968-4e41-9978-34b80fe0a8cf" class="block-editor-block-list__block wp-block is-selected is-reusable block-library-block__reusable-block-container wp-block-block block-editor-block-list__layout">…</div>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/writing-flow.spec.js:1464:5

032fa07 Run

@t-hamano t-hamano added the [Type] Bug An existing feature does not function as intended label Oct 25, 2026
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X3oDSXQzXqDWGmZ2ER5y1U
@t-hamano t-hamano changed the title URL: Recognize schemes with digits, + or - in prependHTTP URL: Make scheme detection in prependHTTP more semantic Oct 25, 2026
claude and others added 2 commits October 25, 2026 07:25
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X3oDSXQzXqDWGmZ2ER5y1U

This branch has not been deployed

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

Labels

[Package] Url /packages/url [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants