Problem/Motivation
Warnings are logged when an RSS feed includes markup with an empty srcset attribute.
Steps to reproduce
- Create a node:
- body:
<source srcset=""/> - format: Full HTML
- promote to front page
- body:
- View
/rss.xml - 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}| Comment | File | Size | Author |
|---|
Issue fork drupal-3195583
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
Comment #2
mohit.bansal623 commentedAdded a check for the same.
Comment #3
xamountIf you go to the culprit view and change the Show Content field to say use Title, you will not get the error. (This doesn't mean the problem is solved by doing this).
See screenshot:
Comment #7
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
As this is a bug it will need a test case to show the issue.
Also an issue summary update for steps to reproduce, proposed solution, remaining tasks, etc. Should follow the default template.
Comment #8
ericdsd commentedHi i experience the same issue on core 9.5.9 and it also generates large error messages that get stored in session table (when trying to debug) which can generate exceding max_allowed_packet error when querying session table on common mysql config.
Comment #9
smokrisUpdated issue summary.
Comment #10
smokrisTest-only patch; should fail.
Comment #11
smokrisFix + test; should pass.
Comment #12
smokrisComment #14
smustgrave commentedtest seems to show the issue pretty clearly.
Followed the steps from the issue summary and definitely see the issue
Patch #11 does solve the issue.
Comment #15
quietone commentedI am doing triage on the core RTBC queue.
The issue summary and proposed resolution are clear and complete. Thank you, that really helps the reviewers and committers. I read the comments this still needs a code review. Setting to Needs review.
I tested this on Drupal 11.x, using the steps in the issue summary and reproduced that problem.
I then took a look at the patch.
Since this is really just checking for an empty string this could be much simpler.
Now, setting to Needs work.
Comment #16
quietone commentedThis also needs a title to say what is being fixed here.
Comment #17
sourabhjainRerolled the patch against 11.x and updated it as suggested in #15.
Comment #18
smustgrave commentedPer #16
Comment #19
smokrisUpdated issue title, as requested.
Comment #20
smustgrave commentedThanks!
Comment #21
xjmPatch does not apply. Thanks!
Comment #22
smokrisRe-rolled for current 11.x-dev.
Comment #23
smustgrave commentedPatch failed to apply.
Comment #24
sourabhjainLet me work on it.
Comment #25
sourabhjainUpdated the patch as per latest 11.x version.
Please review.
Comment #26
smustgrave commented#25 didn't apply either.
I just went ahead and rerolled it
Comment #27
smokrisThanks. #26 has an unnecessary variable assignment which wasn't present in #17. I've attached a modified patch that removes that line (and an interdiff).
Comment #28
smokris(Unintentionally changed issue status. Sorry for the noise.)
Comment #29
smustgrave commentedlets see what the tests say but that line I believe was new to the existing code. But if not needed then good cleanup.
Comment #30
smokrisBoth patches failed. Investigating…
Comment #31
smokrisRevised test data since the transformation now removes empty attribute values.
Comment #32
needs-review-queue-bot commentedThe 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.)
Comment #33
smustgrave commentedThink this was a false positive by the bot.
Comment #34
smustgrave commentedNope needs an MR now and patches hidden.
Comment #36
smokrisCreated https://git.drupalcode.org/project/drupal/-/merge_requests/5355.
Comment #37
xjmI triggered the test-only job for this on GitLab CI. Results:
Comment #38
xjmSaving issue credits.
Comment #41
xjmCommitted to 11.x and 10.2.x, thanks!
This is also eligible for backport to 10.1.x as a non-disruptive bugfix; however, it does not cherry-pick cleanly (nor does #31 apply to 10.1.x). Marking "Needs work" for a 10.1.x backport of the final version of the patch to be created. Thanks!
Comment #43
xjmBetter status.
Comment #45
smokrisThanks, @xjm. Here's an MR for 10.1.x: https://git.drupalcode.org/project/drupal/-/merge_requests/5362
Comment #47
xjmCommitted to 10.1.x. Thanks @smokris!