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.
Comment | File | Size | Author |
---|---|---|---|
#5 | url-fragment-fix-2741379-5.patch | 1.69 KB | laue |
#5 | url-fragment-test-2741379-5.patch | 1.01 KB | laue |
Comments
Comment #2
bpironet CreditAttribution: bpironet commentedI'm at DrupalCon Dublin and start working on this.
Comment #3
bpironet CreditAttribution: bpironet commentedThe 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.
Comment #4
laue CreditAttribution: laue commentedComment #5
laue CreditAttribution: laue at PitechPlus commentedThe 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.
Comment #6
laue CreditAttribution: laue at PitechPlus commentedComment #10
rang501 CreditAttribution: rang501 at ADM Interactive commentedSeems to be duplicate of (and fixed in) #2909349: UrlHelper::parse() is wrong with absolute URLs having fragment but not query
Comment #11
rang501 CreditAttribution: rang501 at ADM Interactive commented