Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Follow-up of #88183: Relative URLs in feeds should be converted to absolute ones
To reproduce
1. Enable twig debug
2. Clear cache
3. Visit /rss.xml
You get an almost empty page and the following error in log/next page:
Warning: DOMDocument::loadXML(): XML declaration allowed only at the start of the document in Entity, line: 6 in Drupal\Core\EventSubscriber\RssResponseRelativeUrlFilter->transformRootRelativeUrlsToAbsolute() (line 47 of core/lib/Drupal/Core/EventSubscriber/RssResponseRelativeUrlFilter.php).
Proposed resolution
If parsing fails, log error and display original XML?
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#12 | 2801097-test.patch | 4.57 KB | dawehner |
#10 | 2801097-10.patch | 5.54 KB | dawehner |
#2 | rss-relative-error-handling-2801097.patch | 997 bytes | Berdir |
Comments
Comment #2
BerdirComment #3
dawehnerShould we alternatively try to strip the twig tags right from the start?
Comment #4
BerdirWe can try that, but I think this could also be useful if there's some other error in the RSS.. unescaped raw content or so that would break it as well. And we shouln't silently drop all output because of that.
Comment #5
dawehnerFair point. IMHO it would be great to open up an issue to try to output twig debug output maybe just in HTML context, whatever this means :)
Comment #6
twistor CreditAttribution: twistor as a volunteer commentedWe absolutely should break the RSS page if the XML is invalid.
There's no room for Postel's law in XML.
Comment #7
BerdirI think you misunderstand the purpose of this change.
Right now we try to parse, fail and *completely hide any kind of output*, making it very hard to debug and figure out what is actually wrong with your XML.
This is not about trying to accept invalid XML, quite the opposite. If we encounter something invalid, then we abort and display it unaltered. So this is the very opposite of postel's law.
Comment #8
twistor CreditAttribution: twistor as a volunteer commentedSounds good to me
Comment #9
dawehnerIMHO this happens quite often, for example when you have some weird embed codes in your html, see #2833987: \Drupal\Core\EventSubscriber\RssResponseRelativeUrlFilter in combination with \Drupal\filter\Plugin\Filter\FilterHtmlCorrector and script tags empty RSS feeds for a duplicated issue. Given that I believe this is major
Comment #10
dawehnerHere is a test for this particularity funny problem.
Comment #11
BerdirCan we get a test-only patch? I trust you, but you know, rules :)
I wrote the actual fix, so can't really RTBC.
Comment #12
dawehnerI had the file locally actually, just didn't uploaded it
Comment #14
Wim LeersRTBC'ing #10.
Comment #17
alexpottCommitted 8f2befb and pushed to 8.3.x. Thanks!
Committed 256756e and pushed to 8.2.x. Thanks!