RSS output not valid when using Twig debug

Created on 7 September 2016, about 8 years ago
Updated 9 August 2024, 30 days ago

Problem/Motivation

When twig debug is turned on the theme hook suggestions are inserted in the templates.
However the insertion of the comments breaks the XML standard.

Implications:
The feed does display with comments in the Views preview pane. However the situation is not ideal as the RSS feed is rejected by many external tools. In particular a developer cannot test integration with third-party services such as IFTTT.

Furthermore the transformRootRelativeUrlsToAbsolute step gets skipped so the feed may contain relative URLs.

Steps to reproduce

  1. create a new drupal project
  2. turn on twig debug
  3. visit the default frontpage feed page (/rss.xml)

Actual behaviour: Eg current feed contents

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'views_view_rss' -->
<!-- BEGIN OUTPUT from 'core/themes/classy/templates/views/views-view-rss.html.twig' -->
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xml:base="http://drupal8rsstwigerror.dd:8083/rss.xml" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Drupal 8</title>
    <link>http://drupal8rsstwigerror.dd:8083/rss.xml</link>
    <description></description>
    <language>en</language>
    
    
  </channel>
</rss>

<!-- END OUTPUT from 'core/themes/classy/templates/views/views-view-rss.html.twig' -->

Proposed resolution

It is the initial comments before the xml tag that cause the problem. The feed should work if these were moved after the xml tag. The new code should only run if twig debug is enabled.

๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Baseย  โ†’

Last updated 21 minutes ago

Created by

๐Ÿ‡ฉ๐Ÿ‡ชGermany tjwelde

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡ง๐Ÿ‡ทBrazil RenatoG Campinas

    I also continue seeing.

    Before patch:

    <!-- THEME DEBUG -->
    <!-- THEME HOOK: 'views_view_rss' -->
    <!-- BEGIN OUTPUT from 'core/modules/views/templates/views-view-rss.html.twig' -->
    <?xml version="1.0" encoding="utf-8"?>
    <rss version="2.0" xml:base="http://drupal10.lndo.site/" xmlns:dc="http://purl.org/dc/elements/1.1/">
      <channel>
        <title>Blog Posts</title>
        <link>http://drupal10.lndo.site/</link>
        <description></description>
        <language>en</language>
        
        
    
    <!-- THEME DEBUG -->
    <!-- THEME HOOK: 'views_view_row_rss' -->
    <!-- BEGIN OUTPUT from 'core/modules/views/templates/views-view-row-rss.html.twig' -->
    <item>
      <title>Second Blog</title>
      <link>http://drupal10.lndo.site/blog-2</link>
      <description>
    
    &lt;!-- THEME DEBUG --&gt;
    &lt;!-- THEME HOOK: &#039;field&#039; --&gt;
    &lt;!-- FILE NAME SUGGESTIONS:
       * field--node--title--blog.html.twig
       x field--node--title.html.twig
       * field--node--blog.html.twig
       * field--title.html.twig
       * field--string.html.twig
       * field.html.twig
    --&gt;
    &lt;!-- BEGIN OUTPUT from &#039;core/modules/node/templates/field--node--title.html.twig&#039; --&gt;
    
    &lt;span&gt;Second Blog&lt;/span&gt;
    
    &lt;!-- END OUTPUT from &#039;core/modules/node/templates/field--node--title.html.twig&#039; --&gt;
    

    After patch:

    <?xml version="1.0" encoding="utf-8"?>
    <rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0" xml:base="http://drupal10.lndo.site/">
      <channel>
        <title>Blog Posts</title>
        <link>http://drupal10.lndo.site/</link>
        <description/>
        <language>en</language>
        
        <item>
      <title>Second Blog</title>
      <link>http://drupal10.lndo.site/blog-2</link>
      <description>
    
    &lt;!-- THEME DEBUG --&gt;
    &lt;!-- THEME HOOK: 'field' --&gt;
    &lt;!-- FILE NAME SUGGESTIONS:
       * field--node--title--blog.html.twig
       x field--node--title.html.twig
       * field--node--blog.html.twig
       * field--title.html.twig
       * field--string.html.twig
       * field.html.twig
    --&gt;
    &lt;!-- BEGIN OUTPUT from 'core/modules/node/templates/field--node--title.html.twig' --&gt;
    
    &lt;span&gt;Second Blog&lt;/span&gt;
    
    &lt;!-- END OUTPUT from 'core/modules/node/templates/field--node--title.html.twig' --&gt;
    
    
    
    &lt;!-- THEME DEBUG --&gt;
    &lt;!-- THEME HOOK: 'field' --&gt;
    &lt;!-- FILE NAME SUGGESTIONS:
       * field--node--uid--blog.html.twig
       x field--node--uid.html.twig
       * field--node--blog.html.twig
       * field--uid.html.twig
       * field--entity-reference.html.twig
       * field.html.twig
    --&gt;
    &lt;!-- BEGIN OUTPUT from 'core/modules/node/templates/field--node--uid.html.twig' --&gt;
    
    &lt;span&gt;
    
  • Merge request !8502TWIG RSS output โ†’ (Open) created by VladimirAus
  • Pipeline finished with Canceled
    3 months ago
    Total: 206s
    #206032
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia VladimirAus Brisbane, Australia

    Creating merge request.

  • Pipeline finished with Failed
    3 months ago
    Total: 221s
    #206034
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia VladimirAus Brisbane, Australia

    VladimirAus โ†’ changed the visibility of the branch 2796453-rss-output-not to hidden.

  • Merge request !8503Twig rss output d11 โ†’ (Open) created by VladimirAus
  • Pipeline finished with Success
    3 months ago
    #206037
  • Status changed to Needs review 3 months ago
  • ๐Ÿ‡ง๐Ÿ‡ทBrazil RenatoG Campinas

    So itโ€™s ready to review?!

    Feel free to update if not yet

  • Status changed to Needs work 3 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Issue summary still appears to need to updating.

    Can the MR be updated to 11.x vs 11.0.x please

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone New Zealand

    Fixes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia VladimirAus Brisbane, Australia

    VladimirAus โ†’ changed the visibility of the branch 2796453-rss-output-not to active.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia VladimirAus Brisbane, Australia

    VladimirAus โ†’ changed the visibility of the branch 2796453-twig-rss-output-d11 to hidden.

  • Status changed to Needs review about 2 months ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia VladimirAus Brisbane, Australia

    Switched to 11.x branch.

  • Pipeline finished with Failed
    about 2 months ago
    #226764
  • Pipeline finished with Failed
    about 2 months ago
    Total: 286s
    #226766
  • Pipeline finished with Success
    about 2 months ago
    Total: 470s
    #226759
  • Pipeline finished with Success
    about 2 months ago
    Total: 467s
    #226769
  • First commit to issue fork.
  • Pipeline finished with Success
    about 2 months ago
    Total: 467s
    #227489
  • Observed test failures, found there are some PHP coding standard related test failures , fixed those.

    pipeline passed successfully & MR is mergeable now.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ankitv18

    $debug_blacklisted = isset($variables['view']) && ($variables['view']->getDisplay()->getType() == 'feed');

    This will output TRUE or FALSE (which was the objective)

    What are your thoughts?

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia VladimirAus Brisbane, Australia

    Makes sense.

  • Pipeline finished with Canceled
    about 2 months ago
    Total: 354s
    #229475
  • Pipeline finished with Failed
    about 2 months ago
    Total: 592s
    #229476
  • Pipeline finished with Failed
    about 2 months ago
    Total: 163s
    #229547
  • Pipeline finished with Success
    about 2 months ago
    Total: 569s
    #229552
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ankitv18

    Pipelines are passing now ~~ keeping this in review for further suggestions.

  • Status changed to Needs work about 2 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Seems like a fix that will need test coverage.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mihaic

    Here rolling patch #43 for Drupal 10.3.1.

  • @smustgrave, Need guidance there for test coverage, As we know issue replicate when theme debug enable, generally when we add test theme debug not visible for those generated test file.

    Any suggestion for how can I enable the theme debug for test files so that to replicate issue for test coverage.

Production build 0.71.5 2024