Closed
Description
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 <a href="https://www.drupal.org">quick</a> 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 <a href="https://www.drupal.org">quick</a> test…"
string(82) "This is a <a href="https://www.drupal.org">quick</a> 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 <a href="https://www.drupal.org">quick</a> 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