Problem/Motivation

Faced in #3375693-27: Fix deprecated assert_options() function usage for PHP 8.3

Running test on debian:buster and newer releases the test fails, faced on PHP 8.3 image as it was updated to the latest debian:bookworm

PHP 8.2 image using libxml libXML Compiled Version => 2.9.10 but 8.3 using 2.9.14

- 8.2 https://dispatcher.drupalci.org/job/drupal_patches/199724/artifact/jenki...
- 8.3 https://dispatcher.drupalci.org/job/drupal_patches/199725/artifact/jenki...

Locally on Ubuntu 23.04 using PHP 8.1 with libxml 2.9.14 the test case also fails, also tested on Alpinelinux 2.11.5 where it also fails independently from PHP version

Previously similar issues with libxml version #3280602-13: Exceptions for CKEditor 5 plugin definitions containing wildcard tags when PHP is built with libxml 2.9.14 @mstrelan suggested

Steps to reproduce

# using 8.2 CI image
core$ docker run --rm -it -v $(pwd):/mnt -w /mnt drupalci/php-8.2-apache:production bash

root@c17f9a60c448:/mnt# php -r 'require __DIR__ . "/autoload.php"; echo \Drupal\Component\Utility\Html::normalize("<");'

# no result rendered

# upgrade libxml2 using https://packages.sury.org/php/README.txt

root@c17f9a60c448:/mnt# curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
root@c17f9a60c448:/mnt# sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ bullseye main" > /etc/apt/sources.list.d/php.list'

# apt update && apt list --upgradable
# apt upgrade -y

root@c17f9a60c448:/mnt# php -r 'require __DIR__ . "/autoload.php"; echo \Drupal\Component\Utility\Html::normalize("<");'
&lt;

All newer libxml returns &lt;

Proposed resolution

- find out

Remaining tasks

- find the cause
- patch/review/commit

User interface changes

no

API changes

no

Data model changes

no

Release notes snippet

Issue fork drupal-3383577

Command icon 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

andypost created an issue. See original summary.

andypost’s picture

Issue summary: View changes

added a bit more to IS

andypost’s picture

Issue summary: View changes
andypost’s picture

Issue summary: View changes

updated steps to reproduce

andypost’s picture

Issue summary: View changes

andypost credited mstrelan.

andypost’s picture

andypost’s picture

Also it reproducible with drush ev 'echo text_summary("<", NULL, 1)."\n";'

andypost’s picture

Manual testing could use following

core$ docker run --rm -it -v $(pwd):/mnt -w /mnt drupalci/php-8.3-apache:production bash
Unable to find image 'drupalci/php-8.3-apache:production' locally
production: Pulling from drupalci/php-8.3-apache
de4cac68b616: Pull complete 
6c3a7f5fe02f: Pull complete 
Digest: sha256:75ee68a6e98792a130eabb1dbd6cfa3dcd8b52fdc4feca5b2b5cd9bdc5b888ea
Status: Downloaded newer image for drupalci/php-8.3-apache:production
root@5c765fed0c54:/mnt# SIMPLETEST_DB=sqlite://./tests.db SIMPLETEST_BASE_URL=http://localhost php vendor/bin/phpunit -c core/phpunit.xml.dist core/modules/text/tests/src/Kernel/TextSummaryTest.php
PHPUnit 9.6.8 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\text\Kernel\TextSummaryTest
..F...                                                              6 / 6 (100%)

Time: 00:05.817, Memory: 4.00 MB

There was 1 failure:

1) Drupal\Tests\text\Kernel\TextSummaryTest::testLength
<pre style="white-space: pre-wrap">&amp;lt;</pre> is identical to <pre style="white-space: pre-wrap"></pre>
Failed asserting that two strings are identical.
....
andypost’s picture

Issue summary: View changes

Narrowed down failure to

php -r 'require __DIR__ . "/autoload.php"; echo \Drupal\Component\Utility\Html::normalize("<");'

It returning different results depending on libxml version

Details edited

The resulting DOM object from \Drupal\Component\Utility\Html::load() is different

object(DOMDocument)#2 (38) {
...
  ["textContent"]=>
  string(0) ""

new versions (PHP 8.3) returns

object(DOMDocument)#2 (40) {
...
  ["textContent"]=>
  string(1) "<"
andypost’s picture

Issue summary: View changes
andypost’s picture

Running following script exposed the error - <body><</body>

the warning (raised on older libxml version) is

PHP Warning:  DOMDocument::loadHTML(): htmlParseStartTag: invalid element name in Entity, line: 4 in /mnt/libxml.php on line 10

the script https://3v4l.org/bBP3r


$document = <<<EOD
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<body><</body>
</html>
EOD;
$dom = new \DOMDocument();
$dom->loadHTML($document, LIBXML_NOBLANKS);
echo $dom->textContent . PHP_EOL;

https://github.com/php/php-src/issues/11469#issuecomment-1699885043

andypost’s picture

PHP maintainers said to file issue to https://gitlab.gnome.org/GNOME/libxml2/-/issues

longwave’s picture

I believe #2441811: Upgrade filter system to HTML5 should make this result consistent on all environments.

andypost’s picture

Status: Active » Needs work

Filed MR to test on PHP 8.3 both html5 and assert_options patches https://git.drupalcode.org/project/drupal/-/merge_requests/4925

andypost’s picture

Status: Needs work » Postponed

As the test passing after #2441811: Upgrade filter system to HTML5

postponing on it

andypost’s picture

Drupal\Tests\media_library\FunctionalJavascript\FieldUiIntegrationTest::testFieldUiIntegration
    Behat\Mink\Exception\ExpectationException: Checkbox "set_default_value" is
    not checked, but it should be.

re-queued and it was random failure

andypost’s picture

andypost’s picture

Status: Postponed » Closed (outdated)

poker10’s picture

Just fyi, this is still relevant for D7, where we cannot change the DOMDocument easily. D7 issue is here: #3397882: [D7 PHP 8.3] TextSummaryTestCase::testLength() fails on some libxml versions

Have you found any workarounds or created a bug report in the libxml2 issue queue (https://gitlab.gnome.org/GNOME/libxml2/-/issues)? Thanks!

andypost’s picture

created a bug report in the libxml2 issue queue

personally I prefer to go this way

joseph.olstad’s picture

There's been 15 releases of libxml2 since 2.9.14
any chance that this issue is fixed in https://gitlab.gnome.org/GNOME/libxml2/-/releases/v2.12.3 v2.12.3?