Problem/Motivation

When parsing URLs, schema-agnostic URLs (for example:

//www.mydomain.com/foo/bar) are incorrectly detected as internal links.

This happens because in setIfExternalOrInternal(), the detection logic checks for the presence of a schema to determine whether a link is external or internal. Since schema-agnostic URLs do not include a schema (e.g. http: or https:), the function treats them as internal and returns early, preventing further processing of the URL components.

As a result, these URLs are not correctly identified as external, and subsequent logic that depends on a complete URL breakdown (host, path, etc.) does not execute properly.

Steps to reproduce

  1. Create or load an entity that contains a field or markup with a schema-agnostic URL (e.g. //example.com/foo/bar).
  2. Trigger the processing path where setIfExternalOrInternal() is invoked.
  3. Observe that the function returns early, marking the URL as internal.
  4. As a result, the host and other URL components are never populated.

Proposed resolution

Update setIfExternalOrInternal() to correctly handle schema-agnostic URLs:

  • Detect host and scheam, not only schema

Remaining tasks

  • Detect host and scheam, not only schema

User interface changes

None.

API changes

None.

Data model changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

juanjol created an issue. See original summary.

juanjol’s picture

Version: 1.0.x-dev » 1.x-dev
juanjol’s picture

Title: Host not populated in processHrefAndSetComponents() » Internal or external links are not
Issue summary: View changes
juanjol’s picture

Issue description as I really found the problem to be on setInternalorExternal function.

juanjol’s picture

Status: Active » Needs review

I’ve noticed that the logic in setIfExternalOrInternal() is not entirely correct and its responsibilities are not clearly defined. This is causing certain URLs—such as schema-agnostic ones—to be detected incorrectly.

Additionally, the current implementation marks all iframes as “external,” but that’s not always accurate. An iframe can contain internal content if it embeds another part of the same site.

I believe this logic should be refactored to better separate responsibilities:

The function should focus only on determining whether a URL is internal or external, without making assumptions based on the element type (like iframes).

Schema-agnostic URLs (starting with //) should be correctly handled as potentially external links, depending on their host.

Issue/MR moved to "Needs review".

juanjol’s picture

Title: Internal or external links are not » Internal or external links are not correctly detected on schema agnostic urls

juanjol’s picture

Status: Needs review » Needs work

Looks like the shouldRegisterTarget logic must be updated too, working on it

lpeidro’s picture

Status: Needs work » Fixed

Hello Juanjo.

Thnak you very much for your support. I merge de issue.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.