Got a strange one today. It's possible this is a support request, I'm uncertain.

I have a node type with a title and a URL field, only displaying URI's. The entire point of the node is a link, so having a node title was redundant in this case.

I then have a view that has the URL (hidden) then the title is displayed with "Output this field as a custom link" checked off, and {{ field_url }} placed as the replacement link.

This has been working great for a few weeks, but I came across a strange edge case today.

When the URL has an anchor in it, for example:

https://uptimerobot.com/dashboard.php#mainDashboard

The URL that's rendered by Views is:

https://uptimerobot.com/dashboard.phpmainDashboard

with the # tag stripped out - a broken link.

There's a fairly easy workaround. Instead of "Output this field as a custom link" on the title field, I can select "Override the output of this field with custom text" and type in:

<a href="{{ field_url }}">{{ title }}</a>

and it works great.

I've tried different combinations of settings, but it seems that "Output this field as a custom link" is inadvertently stripping the fragment identifier prefix (#) out of URIs.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TrevorBradley created an issue. See original summary.

bpironet’s picture

I'm at DrupalCon Dublin and start working on this.

bpironet’s picture

The issue seems to be related to the striptags() in the function renderAsLink() of the file FieldPluginBase.php (core/modules/views/src/Plugin/views/field/FieldPluginBase.php).

The striptags remove the and and the rest of the function does not use the original value to render the anchor correctly.

laue’s picture

Assigned: Unassigned » laue
laue’s picture

The problem starts from Drupal\Component\Utility\UrlHelper::parse(), which doesn't correctly parse an absolute URL that has a fragment but doesn't have a query. For example, http://example.com/foo?foo=bar#foo will be correctly parsed but http://example.com/foo#foo won't.

laue’s picture

Assigned: laue » Unassigned
Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: url-fragment-fix-2741379-5.patch, failed testing.

The last submitted patch, 5: url-fragment-test-2741379-5.patch, failed testing.

The last submitted patch, 5: url-fragment-fix-2741379-5.patch, failed testing.

rang501’s picture