Problem/Motivation

When I create an RSS Feed view and assign the RSS setting "Link" to my path field added to the View, I'm receiving the following (example):

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">InvalidArgumentException</em>: The internal path component &#039;http://cmslocal.gfs.com/en-us/ideas/minding-the-menu-labeling-law&#039; is external. You are not allowed to specify an external URL together with internal:/.

It seems like at some point the "Path" content field within Views now outputs an absolute URL. Or at least it does for me and I can't change it, even with the checkbox "Use absolute link (begins with "http://")" unchecked. Perhaps it's because my project is using the Domain module.

Regardless, I believe the RSS row plugin should allow both absolute and relative. I'm not sure there's a good reason it doesn't?

Steps to reproduce

  1. Create a views RSS feed display.
  2. Configure the display to show fields: Format > Show: Fields
  3. Add all required fields to the display.
  4. For the link field, use "Link to Content" and enable "Use absolute link" for this field.
  5. Configure the display's RSS fields:
    • Map the link field to the link field create above in #4.
    • Map the GUID field to the link field create above in #4, and enable "GUID is permalink".
  6. Save the view - however the preview most likely already failed
  7. View the page for the RSS feed
  8. Bug:
    The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">InvalidArgumentException</em>: The internal path component &#039;http://cmslocal.gfs.com/en-us/ideas/minding-the-menu-labeling-law&#039; is external. You are not allowed to specify an external URL together with internal:/.
    

Proposed resolution

Update the \Drupal\views\Plugin\views\row\RssFields to detect absolute links and output them correctly.

Remaining tasks

None

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

NA

Issue fork drupal-2918784

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

Anonymous’s picture

vilepickle created an issue. See original summary.

Anonymous’s picture

Issue summary: View changes
Anonymous’s picture

StatusFileSize
new1.52 KB

Here is a first patch

Anonymous’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: 2918784_allow_rss_link_absolute_urls.patch, failed testing. View results

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mstef’s picture

Works for me (8.5.3)

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

shawnb’s picture

The patch works for me as well (8.6.3)

sfdrummer’s picture

I've had a similar problem with the RSS formatter messing up links. A link like https://example.com/insights/news/news-article was being output as https://example.com/news/news-article. So this renders the RSS feed unusable, and checking "Use absolute link" causes the issue with the external link.

The way I've managed to fix this (which I don't like), is to check "Output the URL as text" for the "Link to content" field. Then under "Rewrite results" select "Override the output of this field with custom text", and enter "/ /{{ view_node }}".

This looks to me like a URL being exploded by "/" and the wrong segment being stripped perhaps. Hope this helps someone.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jennypanighetti’s picture

StatusFileSize
new1.46 KB
new507 bytes

Updated patch for 8.7.x.

jennypanighetti’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 12: 2918784-views_rss_link.patch, failed testing. View results

jennypanighetti’s picture

StatusFileSize
new1.88 KB

Ignore patch #12, it broke other items. Trying this patch instead.

rakesh.gectcr’s picture

Status: Needs work » Needs review

@jennypanighetti I am changing the status to needs review, Sot that the test will against your new patch.

Thanks,
Rakesh James

drup16’s picture

StatusFileSize
new1.89 KB

reroll for core v8.7.7.

patch seems to be giving error at error: patch failed: core/modules/views/src/Plugin/views/row/RssFields.php:6

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

drcolossos’s picture

StatusFileSize
new1.99 KB

The patches seem to be mixed up. This is a re-roll against the latest 8.7.x.

jennypanighetti’s picture

That patch failed for me:

Hunk #1 FAILED at 4.
Hunk #2 FAILED at 142.
Hunk #3 succeeded at 270 with fuzz 1 (offset 56 lines).
jennypanighetti’s picture

StatusFileSize
new1.7 KB
agrochal’s picture

StatusFileSize
new3.39 KB

I attach interdiff file for last two patches(#19 and #21).

agrochal’s picture

StatusFileSize
new3.39 KB

The same interdiff as in #22, just changed name to be proper.

Anonymous’s picture

Version: 8.9.x-dev » 8.7.x-dev
Status: Needs review » Closed (outdated)

It seems that this ended up getting fixed in Drupal 8.8.

See https://www.drupal.org/project/drupal/issues/2673980

Anonymous’s picture

jrearick’s picture

Version: 8.7.x-dev » 8.9.x-dev
Status: Closed (outdated) » Needs work

I don't think #2673980 resolved the issue. On a fresh build of 8.9.* I'm still getting the error. Here's how I can create it.

* Fresh install of Drupal 8.9.x
* Add a link field to a content type. Allow it to contain external links
* Add content with external links in that field
* Create a view with a Feed display
* Format Show Fields
* Add the required fields (title, my link field, body, authored by authored on)
* Configure the row style options, with Content: my link field as the link field (and the rest as figured)
* Add a path and save
* Observe the following error when trying to access the feed url:

InvalidArgumentException: The internal path component 'http://example.com' is external. You are not allowed to specify an external URL together with internal:/. in Drupal\Core\Url::fromInternalUri() (line 411 of core/lib/Drupal/Core/Url.php).
Drupal\Core\Url::fromUri('internal:/http://example.com', Array) (Line: 210)
Drupal\Core\Url::fromUserInput('/http://example.com') (Line: 228)
Drupal\views\Plugin\views\row\RssFields->getAbsoluteUrl(Object) (Line: 142)
Drupal\views\Plugin\views\row\RssFields->render(Object) (Line: 121)
Drupal\views\Plugin\views\style\Rss->render(Array) (Line: 152)
Drupal\views\Plugin\views\display\Feed->render() (Line: 1533)
Drupal\views\ViewExecutable->render() (Line: 128)
Drupal\views\Plugin\views\display\Feed->execute() (Line: 1630)
Drupal\views\ViewExecutable->executeDisplay('feed_1', Array) (Line: 77)
Drupal\views\Element\View::preRenderViewElement(Array)
call_user_func_array(Array, Array) (Line: 100)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. Support for this callback implementation is deprecated in 8.8.0 and will be removed in Drupal 9.0.0. See https://www.drupal.org/node/2966725', 'silenced_deprecation', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 781)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 372)
Drupal\Core\Render\Renderer->doRender(Array, 1) (Line: 200)
Drupal\Core\Render\Renderer->render(Array, 1) (Line: 144)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 145)
Drupal\Core\Render\Renderer->renderRoot(Array) (Line: 109)
Drupal\views\Plugin\views\display\Feed::buildResponse('test', 'feed_1', Array) (Line: 53)
Drupal\views\Routing\ViewPageController->handle('test', 'feed_1', Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 694)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
jrearick’s picture

Status: Needs work » Needs review
StatusFileSize
new1.89 KB

Okay. I took what @jennypanighetti did in #21 and re-rolled it for 8.9.x. I also found the same/similar issue if you use the link as the guid, so I added that in. Hopefully I formatted this patch correctly.

jrearick’s picture

Of course a composer build doesn't give the right base for the patch file. Trying this one.

sivaji_ganesh_jojodae’s picture

Assigned: » Unassigned
dww’s picture

Adding #3090267: Improve behaviour of RSS view with fields if you enabled "Use absolute link" as another related. That might be duplicate with this -- I didn't see this issue when I submitted that one as a follow-up to #2673980: RSS view with fields give wrong URL from path field.

No time to closely review all this just yet, but I'll try to look soon.

Thanks,
-Derek

xem8vfdh’s picture

I have the opposite problem. I set my RSS feed up years ago and it's worked fine while my RSS publisher published fully qualified URLS. They suddenly switched to publishing relative paths, and now my system broke with the same error in OP.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

jennypanighetti’s picture

StatusFileSize
new2.6 KB

Re-rolled patch #28 for Drupal 8.8.x (starting from 8.8.5)

sivaji_ganesh_jojodae’s picture

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

The patch couldn't be applied on 9.x.

Tagging "Needs tests" to confirm that the bug is present & needs a patch to fix.

vsujeetkumar’s picture

Assigned: Unassigned » vsujeetkumar
vsujeetkumar’s picture

Assigned: vsujeetkumar » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.89 KB

Re-roll patch created for 9.1.x, Please review.

ronaldmulero’s picture

StatusFileSize
new69.63 KB

#36 works for me.
Thank you vsujeetkumar!

Drupal core 8.9.2

Configured the Link field of the View like this:
Link field configs in Feeds view

dww’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/views/src/Plugin/views/row/RssFields.php
    @@ -6,6 +6,7 @@
    @@ -58,7 +59,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    
    @@ -58,7 +59,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
         $form['link_field'] = [
           '#type' => 'select',
           '#title' => $this->t('Link field'),
    -      '#description' => $this->t('The field that is going to be used as the RSS item link for each row. This must either be an internal unprocessed path like "node/123" or a processed, root-relative URL as produced by fields like "Link to content".'),
    +      '#description' => $this->t('The field that is going to be used as the RSS item link for each row.'),
           '#options' => $view_fields_labels,
           '#default_value' => $this->options['link_field'],
           '#required' => TRUE,
    

    #36 is missing this hunk from #33, which should have been preserved. EDIT: Nope, sorry. This patch shouldn't touch that description (which I helped add!). Ignore this point.

  2. +++ b/core/modules/views/src/Plugin/views/row/RssFields.php
    @@ -156,7 +164,14 @@ public function render($row) {
    +      // If guid is internal link, get absolute URL from URI
    

    If the guid is an internal link, get the absolute URL from the URI.

  3. #NeedsTests. ;)

Cheers,
-Derek

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kasey_mk’s picture

Thank you; #36 worked for me

vsujeetkumar’s picture

Status: Needs work » Needs review
StatusFileSize
new1.91 KB
new636 bytes

Worked on #38. Please have a look.
#38.1: Ignore this point as mentioned in #38.
#38.2: Changes has been done.

Status: Needs review » Needs work

The last submitted patch, 42: 2918784_42.patch, failed testing. View results

vsujeetkumar’s picture

Status: Needs work » Needs review

Re-test the last patch, Moved to NR. Please have a look.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Was tagged for tests in #34 which still needs to happen.

Did not test patch.

omahm’s picture

#42 Patch works for me (9.5.5 PHP 8.1) for a site running the Domain module. One caveat is that if you have Twig debugging enabled the field comments will passed into fromURI() which isn't a problem on production sites.
InvalidArgumentException: The URI ' <!-- THEME DEBUG --> <!-- THEME HOOK: 'views_view_field' --> <!-- BEGIN OUTPUT from 'core/themes/stable/templates/views/views-view-field.html.twig' -->

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

douggreen’s picture

StatusFileSize
new1.88 KB

Attached patch is a small code cleanup to not duplicate calling $this->getField($row_index, $this->options['link_field']) twice.

douggreen’s picture

StatusFileSize
new1.88 KB

Oops, this fixes a syntax error.

recrit’s picture

StatusFileSize
new1.83 KB
new679 bytes

Updated patch with further cleanup of duplicate calls to $this->getField($row_index, $this->options['link_field'])

recrit’s picture

StatusFileSize
new2.02 KB
new1.82 KB

The attached patch will fix the errors with twig debugging enabled. Core without this patch would not error but would create urls were invalid - "http://www.mysite.com/%20%3C%21--%20THEME%20DEBUG%20--%3E%20%3C%21--%20T..."

recrit’s picture

Pending: new test to test an external url used for the RSS link.

recrit’s picture

StatusFileSize
new5.5 KB
new3.47 KB
new3.47 KB

The attached patches add the new feed field test to check field configured to output an absolute URL.

  • "2918784-55--fix-and-tests.patch": This is the fix from #54 along with the new tests. This should PASS.
  • "2918784-55--tests-only.patch": This is 11.x with the new tests. This should FAIL.

NOTE: The patch "2918784-55--fix-and-tests.patch" also applies to 10.1.x.

recrit’s picture

Status: Needs work » Needs review
smustgrave’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: -Needs tests +Needs issue summary update

Issue summary should be updated, not super clear what the proposed solution is.

Added the template to be filled in by someone familiar with the issue.

Removing tests tag as #56 shows they were added.

recrit’s picture

Issue summary: View changes
recrit’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs issue summary update

Removing IS update tag as that was completed in #59

Following the steps in the IS I was able to reproduce the issue
Patch #58 did solve it, and reran the tests for php8.2 and think failure was unrelated.
Also tests-only patch was provided in #58 that shows the issue.

Think this one is good.

The last submitted patch, 56: 2918784-55--fix-and-tests.patch, failed testing. View results

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work

The Needs Review Queue Bot tested this issue.

While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

recrit’s picture

Status: Needs work » Reviewed & tested by the community

I created the following MRs: with 2918784-55--fix-and-tests.patch
11.x: MR 5437
10.1.x: MR 5438

longwave’s picture

Status: Reviewed & tested by the community » Needs work

Added some feedback to the MR.

kasey_mk’s picture

I'm getting an error that You are not allowed to specify an external URL together with internal:/. in Drupal\Core\Url::fromInternalUri() which is annoying because that's exactly what I want to do: our feeds may link to content on the same domain using the view_node internal link to content, or on one of our other domains using a link field which may contain an external absolute link.

The #15 fix on Improve behavior of RSS view with fields if you enabled "Use absolute link" lets me mix'n'match as I need to by allowing valid absolute links to pass right through the getAbsoluteUrl function.

There's obviously a lot more going on in this MR but I'm hoping that at the end of the day, I can be allowed to specify external URLs together with internal. Thanks!

recrit’s picture

Status: Needs work » Needs review

the following MR's have been updated per the MR feedback on MR 5438:
11.x: MR 5437
10.1.x: MR 5438

recrit’s picture

StatusFileSize
new5.76 KB

attached a 11.x static patch for composer builds

smustgrave changed the visibility of the branch 2918784-10.1.x to hidden.

smustgrave’s picture

Status: Needs review » Needs work

Hiding the 10.1 so we just have the 11.x MR.

For the comments around using trim() and striptags()

Depending on the views configuration, the $this->getField($row_index, $this->options['link_field']); could return markup.

If this is needed for the fix believe we maybe should have coverage also around when markup is used. To show that it is indeed needed.

Thanks.

jennypanighetti’s picture

I just upgraded to 10.3.x and it said the patch failed.. which one should I use for 10.3.1?

nicoleannevella’s picture

Any updates on this?

I'm using a Link field in an RSS feed view and have it set to display "link only" and "show URL as plain text" and I am still getting the error as drupal is expecting a relative link.

Can we not use absolute (external) urls in RSS feeds? I think that option should be available.

Using drupal 10.4.6

liam morland made their first commit to this issue’s fork.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.