Skip to content
Snippets Groups Projects

Issue #2918784: Views RSS row plugin incorrectly assumes links are relative

Open Issue #2918784: Views RSS row plugin incorrectly assumes links are relative
2 unresolved threads
Open Michael Vanetta requested to merge issue/drupal-2918784:2918784-10.1.x into 10.1.x
2 unresolved threads
Files
3
@@ -2,6 +2,7 @@
namespace Drupal\views\Plugin\views\row;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
@@ -130,7 +131,18 @@ public function render($row) {
// Create the RSS item object.
$item = new \stdClass();
$item->title = $this->getField($row_index, $this->options['title_field']);
$item->link = $this->getAbsoluteUrl($this->getField($row_index, $this->options['link_field']));
// If internal link, get absolute URL from URI.
$link = $this->getField($row_index, $this->options['link_field']);
$link = $link ? trim(strip_tags($link)) : '';
    • Why do we need trim and strip_tags? I ran the tests without this and they also pass.

      • Depending on the views configuration, the $this->getField($row_index, $this->options['link_field']); could return markup. In order to use UrlHelper::isExternal($link), this needs to be a clean url.

      • Please register or sign in to reply
Please register or sign in to reply
if ($link) {
if (!UrlHelper::isExternal($link)) {
$item->link = $this->getAbsoluteUrl($link);
}
else {
$item->link = Url::fromUri($link)->setAbsolute()->toString();
}
}
$field = $this->getField($row_index, $this->options['description_field']);
$item->description = is_array($field) ? $field : ['#markup' => $field];
@@ -147,7 +159,17 @@ public function render($row) {
$item_guid = $this->getField($row_index, $this->options['guid_field_options']['guid_field']);
if ($this->options['guid_field_options']['guid_field_is_permalink']) {
$guid_is_permalink_string = 'true';
$item_guid = $this->getAbsoluteUrl($item_guid);
$item_guid = $item_guid ? trim(strip_tags($item_guid)) : '';
// If the guid is an internal link, get the absolute URL from the URI.
if ($item_guid) {
if (!UrlHelper::isExternal($item_guid)) {
$item_guid = $this->getAbsoluteUrl($item_guid);
}
else {
$item_guid = Url::fromUri($item_guid)->setAbsolute()->toString();
}
}
}
$item->elements[] = [
'key' => 'guid',
Loading