Cannot use <nolink> in link fields in default content

Created on 29 March 2025, 11 days ago

Problem/Motivation

When using <nolink> as the destination URL on a link field that is imported using default content, the import fails with this error:

The URI '<nolink&gtl;' is invalid. You must use a valid URI scheme.

Steps to reproduce

Have default content that includes a link field.

Proposed resolution

Allow link fields with the value '<nolink&gtl;' to be imported using default content.

Remaining tasks

Fix the bug.
Add test coverage.

User interface changes

n/a

Introduced terminology

n/a

API changes

TBC

Data model changes

TBC

Release notes snippet

TBC

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

link.module

Created by

🇺🇸United States DamienMcKenna NH, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @DamienMcKenna
  • 🇺🇸United States DamienMcKenna NH, USA

    For consideration:

    diff --git a/core/lib/Drupal/Core/Url.php b/core/lib/Drupal/Core/Url.php
    index d16ef550651..b3a8e0e0d41 100644
    --- a/core/lib/Drupal/Core/Url.php
    +++ b/core/lib/Drupal/Core/Url.php
    @@ -276,6 +276,11 @@ public static function fromUserInput($user_input, $options = []) {
        * @see \Drupal\Core\Url::fromUserInput()
        */
       public static function fromUri($uri, $options = []) {
    +    // Special handling for <nolink>.
    +    if ($uri == '<nolink>') {
    +      return Url::fromRoute('<nolink>');
    +    }
    +
         // parse_url() incorrectly parses base:number/... as hostname:port/...
         // and not the scheme. Prevent that by prefixing the path with a slash.
         if (preg_match('/^base:\d/', $uri)) {
    
  • First commit to issue fork.
  • 🇺🇸United States dcam

    I don't know why it thinks I made an MR. It is not my intention to work on this issue.

    I did look at this page earlier. This isn't the first time D.o has randomly opened MRs on my behalf after I've glanced at an issue.

  • 🇺🇸United States smustgrave

    No worries @dcam happens all the time.

    Am moving back to NW as there should be an MR and test

  • 🇺🇸United States DamienMcKenna NH, USA

    Is this the correct approach or are there other considerations or appraoches to fixing this that I didn't take into account?

  • First commit to issue fork.
  • Pipeline finished with Failed
    5 days ago
    Total: 120s
    #465454
  • Pipeline finished with Failed
    5 days ago
    Total: 122s
    #465465
  • 🇺🇸United States smustgrave

    Pipeline has issues, have not reviewed.

Production build 0.71.5 2024