Skip to content

LinkControl doesn't prepend https:// when submitting URLs without selecting suggestions #75374

@getdave

Description

@getdave

What

When using LinkControl (e.g., in Navigation blocks), typing a URL like wordpress.org or www.wordpress.org and pressing Enter does not auto-prepend https:// to the URL. The URL is saved as-is without a protocol.

Current behavior:

  • Type wordpress.org → Press Enter → Saves as wordpress.org
  • Type www.wordpress.org → Press Enter → Saves as www.wordpress.org

Expected behavior:

  • Type wordpress.org → Press Enter → Should save as https://wordpress.org
  • Type www.wordpress.org → Press Enter → Should save as https://www.wordpress.org

This works correctly when selecting a suggestion from the dropdown (the search handler calls prependHTTPS), but fails when directly submitting without selecting a suggestion.

Why

URLs without protocols are invalid and won't work as links. The Buttons block test explicitly verifies this behavior should work (see test/e2e/specs/editor/blocks/buttons.spec.js lines 134-142), and PR #75005 updated the codebase to use https as the default protocol.

This creates an inconsistent UX where:

  • Selecting a suggestion: URL gets prepended with https://
  • Pressing Enter directly: URL stays as-is without protocol ❌

The Button block is unaffected because it has a workaround in get-updated-link-attributes.js that calls prependHTTPS() separately. However, Navigation blocks and other blocks using LinkControl are affected.

How

The issue is in packages/block-editor/src/components/link-control/search-input.js line 164.

When submitting without a suggestion, the code passes:

onSuggestionSelected( hasSuggestion || { url: value } );

It should call prependHTTPS() on the value:

import { prependHTTPS } from '@wordpress/url';

// In onSubmit handler:
onSuggestionSelected( hasSuggestion || { url: prependHTTPS( value ) } );

This matches how the search handler's handleDirectEntry function already works in use-search-handler.js line 44.

User Stories

As a user creating a navigation menu, I want to type wordpress.org and have it automatically saved as https://wordpress.org, so my links work correctly without requiring me to remember the protocol.

As a user, I want consistent behavior whether I select a suggestion from the dropdown or press Enter directly, so I don't have to think about which method properly formats my URL.

Metadata

Metadata

Labels

[Feature] Link EditingLink components (LinkControl, URLInput) and integrations (RichText link formatting)[Package] Block editor/packages/block-editor[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions