Skip to content

PHP 8.3 regression DomNode->value setting #11469

Closed
@andypost

Description

@andypost

Description

The following code:

<?php
$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>
<img data-caption="This is a &lt;a href=&quot;https://www.drupal.org&quot;&gt;quick&lt;/a&gt; test…" src="llama.jpg" />
</body>
</html>
EOD;
$dom = new \DOMDocument();
$dom->loadHTML($document, LIBXML_NOBLANKS);
$xpath = new \DOMXPath($dom);
foreach ($xpath->query('//@*[starts-with(name(.), "data-")]') as $node) {
  $value = $node->value;
  var_dump($value);
  $value = htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
  var_dump($value);
  $node->value = $value;
  var_dump($node->value);
}

Resulted in this output:

string(60) "This is a <a href="https://www.drupal.org">quick</a> test…"
string(82) "This is a &lt;a href=&quot;https://www.drupal.org&quot;&gt;quick&lt;/a&gt; test…"
string(82) "This is a &lt;a href=&quot;https://www.drupal.org&quot;&gt;quick&lt;/a&gt; test…"

But I expected this output instead:

string(60) "This is a <a href="https://www.drupal.org">quick</a> test…"
string(82) "This is a &lt;a href=&quot;https://www.drupal.org&quot;&gt;quick&lt;/a&gt; test…"
string(60) "This is a <a href="https://www.drupal.org">quick</a> test…"

This is a cause of few tests failed in Drupal HEAD https://www.drupal.org/project/drupal/issues/3366843

PHP Version

PHP 8.3.0-alpha1

Operating System

Alpinelinux, Debian

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions