If a view mode is set to have an onclick attribute, whose value comes from a token that gives an external url, an uncaught InvalidArgumentException is thrown.

This is happening because DS supposes that the token will return an internal uri, which is not always the case.

Example case: The entity has a link field, which has an external url in the link's value.

The problem is in ds.module @ line 561 :

      $url = Url::fromUri('internal:/' . $url);

This supposes that the $url will always be internal.

Steps to reproduce:

  1. Create a link field to a node (or any other entity)
  2. Create a node and type an external url to this field, for example https://www.drupal.org
  3. Go to admin/structure/types/manage/YOUR_NODE_BUNDLE/display and select a Display Suite layout
  4. At the Custom wrappers select Add link > Tokens and in the Custom link use your field token: [node:field_link:uri]

Now if you clear caches and try to visit your node, you will get a WSOD with InvalidArgumentException:

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">InvalidArgumentException</em>: The internal path component &#039;https://www.drupal.org&#039; is external. You are not allowed to specify an external URL together with internal:/. in <em class="placeholder">Drupal\Core\Url::fromInternalUri()</em> (line <em class="placeholder">410</em> of <em class="placeholder">core/lib/Drupal/Core/Url.php</em>). <pre class="backtrace">Drupal\Core\Url::fromUri(&#039;internal:/https://www.drupal.org&#039;) (Line: 561)

Comments

efpapado created an issue. See original summary.

efpapado’s picture

Status: Active » Needs review
StatusFileSize
new749 bytes

Attaching patch.

aspilicious’s picture

We need a test for this so we don't brake this again in the future. (both internal and external url)

aspilicious’s picture

Status: Needs review » Needs work
karlshea’s picture

StatusFileSize
new789 bytes

If you're using a LinkIt field the URI already has "internal:/" prepended, so that needs to be checked as well.

karlshea’s picture

StatusFileSize
new593 bytes

Also support entity: protocol

karlshea’s picture

StatusFileSize
new826 bytes

Oops!

swentel’s picture

Status: Needs work » Needs review

go bot

swentel’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Looks good (tested manually too).
We do need tests though,

swentel’s picture

Status: Needs work » Closed (duplicate)

Fixed in #2883928: Use absolute or external URL for link wrappers (without tests, but was fine manually)