Problem/Motivation

Using Drupal 9.3.6 and upgraded from PHP 7.4 to PHP 8.1

Now I get the following error:

Deprecated function: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Component\Utility\Html::escape() (line 424 of core/lib/Drupal/Component/Utility/Html.php).
Drupal\Component\Utility\Html::escape(NULL) (Line: 125)
Drupal\feeds\Controller\ItemListController->listItems(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 317)
Drupal\cleantalk\EventSubscriber\BootSubscriber->handle(Object, 1, 1) (Line: 49)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 57)
Drupal\advban\AdvbanMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 265)
Drupal\shield\ShieldMiddleware->bypass(Object, 1, 1) (Line: 221)
Drupal\shield\ShieldMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Comments

jsidigital created an issue. See original summary.

jsidigital’s picture

Issue tags: +PHP 8.1
jsidigital’s picture

StatusFileSize
new1.76 KB

Managed to get error out with the attached patch that is based on similar issue here:
https://www.drupal.org/project/drupal/issues/3255637

Not sure if that works for anyone else or if it passes tests.

Would appreciate it if someone double checks that.

Thank you.

cilefen’s picture

Status: Active » Needs review
larowlan’s picture

Project: Drupal core » Feeds
Version: 9.3.x-dev » 8.x-3.x-dev
Component: other » Code
Issue tags: +Bug Smash Initiative

The trace shows this is coming from the feeds module

megachriz’s picture

StatusFileSize
new2.2 KB

Does this fix the issue?

megachriz’s picture

Title: Deprecated htmlspecialchars() on Html.php using PHP 8.1 » PHP 8.1: do not pass null to Html::escape() and Unicode::truncate().
megachriz’s picture

StatusFileSize
new2.31 KB

I just tested the patch manually with PHP 8.1. It turns out sanitizing isn't necessary. The value <script>alert('hi')</script> would get displayed as &lt;script&gt;alert(&#039;hi&#039;)&lt;/script&gt;.

So the attached patch removes the Html::escape() call.
Will commit it if tests still pass.

  • MegaChriz committed 4009113 on 8.x-3.x
    Issue #3266704 by MegaChriz: Fixed PHP 8.1: do not pass null to Html::...
megachriz’s picture

Status: Needs review » Fixed

Committed #8.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.