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
- Create or load an entity that contains a field or markup with a schema-agnostic URL (e.g.
//example.com/foo/bar). - Trigger the processing path where
setIfExternalOrInternal()is invoked. - Observe that the function returns early, marking the URL as internal.
- 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.
Issue fork entity_mesh-3553346
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
Comment #2
juanjolComment #3
juanjolComment #4
juanjolIssue description as I really found the problem to be on setInternalorExternal function.
Comment #5
juanjolI’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".
Comment #6
juanjolComment #8
juanjolLooks like the shouldRegisterTarget logic must be updated too, working on it
Comment #9
lpeidro commentedHello Juanjo.
Thnak you very much for your support. I merge de issue.