Fix warning when RSS feed includes markup with an empty srcset attribute

Created on 30 January 2021, about 4 years ago
Updated 13 November 2023, over 1 year ago

Problem/Motivation

Warnings are logged when an RSS feed includes markup with an empty srcset attribute.

Steps to reproduce

  1. Create a node:
    • body: <source srcset=""/>
    • format: Full HTML
    • promote to front page
  2. View /rss.xml
  3. The following error message is logged:
    Warning: Uninitialized string offset 0 in Drupal\Component\Utility\Html::transformRootRelativeUrlsToAbsolute() (line 486 of /var/www/html/web/core/lib/Drupal/Component/Utility/Html.php)

Proposed resolution

Don't assume that the srcset attribute has a non-empty string — instead, check and skip the absolute-URL transformation if there is no URL.

Remaining tasks

Review.
Update title to state what is being fixed

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Release notes snippet

n/a

Original report by mxmilkiib

I'm not sure if this is the right component to log this under. It's from https://libreav.org, the site is mostly about Feeds. I keep getting runs of this errors in the logs, but it's apparently not directly related to feed import times. It does say Rss though, but IDK!

Notice: Uninitialized string offset: 0 in Drupal\Component\Utility\Html::transformRootRelativeUrlsToAbsolute() (line 474 of /var/www/html/core/lib/Drupal/Component/Utility/Html.php)

#0 /var/www/html/core/includes/bootstrap.inc(305): _drupal_error_handler_real()
#1 /var/www/html/core/lib/Drupal/Component/Utility/Html.php(474): _drupal_error_handler()
#2 /var/www/html/core/lib/Drupal/Core/EventSubscriber/RssResponseRelativeUrlFilter.php(63): Drupal\Component\Utility\Html::transformRootRelativeUrlsToAbsolute()
#3 /var/www/html/core/lib/Drupal/Core/EventSubscriber/RssResponseRelativeUrlFilter.php(29): Drupal\Core\EventSubscriber\RssResponseRelativeUrlFilter->transformRootRelativeUrlsToAbsolute()
#4 [internal function]: Drupal\Core\EventSubscriber\RssResponseRelativeUrlFilter->onResponse()
#5 /var/www/html/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func()
#6 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(191): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#7 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(179): Symfony\Component\HttpKernel\HttpKernel->filterResponse()
#8 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#9 /var/www/html/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle()
#10 /var/www/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle()
#11 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(191): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#12 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(128): Drupal\page_cache\StackMiddleware\PageCache->fetch()
#13 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(82): Drupal\page_cache\StackMiddleware\PageCache->lookup()
#14 /var/www/html/modules/contrib/advban/src/AdvbanMiddleware.php(57): Drupal\page_cache\StackMiddleware\PageCache->handle()
#15 /var/www/html/core/modules/ban/src/BanMiddleware.php(50): Drupal\advban\AdvbanMiddleware->handle()
#16 /var/www/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\ban\BanMiddleware->handle()
#17 /var/www/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#18 /var/www/html/modules/remove_http_headers/src/StackMiddleware/RemoveHttpHeadersMiddleware.php(49): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#19 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\remove_http_headers\StackMiddleware\RemoveHttpHeadersMiddleware->handle()
#20 /var/www/html/core/lib/Drupal/Core/DrupalKernel.php(706): Stack\StackedHttpKernel->handle()
#21 /var/www/html/index.php(19): Drupal\Core\DrupalKernel->handle()
#22 {main}
🐛 Bug report
Status

Fixed

Version

10.1

Component
Base 

Last updated about 1 hour ago

Created by

🇬🇧United Kingdom mxmilkiib

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024