1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/ext/dom/tests/gh17847.phpt
Niels Dossche 2c45d67ad3 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix xinclude destruction of live attributes
2025-03-18 22:04:13 +01:00

53 lines
1.1 KiB
PHP

--TEST--
GH-17847 (xinclude destroys live node)
--EXTENSIONS--
dom
--FILE--
<?php
$doc = new DOMDocument();
$doc->loadXML(<<<XML
<root>
<xi:include href="thisisnonexistent" xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:fallback>fallback<p>garbage</p></xi:fallback>
<p>garbage</p>
</xi:include>
<xi:test xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="thisisnonexistent">
<p attr="foo" attr2="bar">garbage</p>
</xi:include>
</xi:test>
</root>
XML);
$xpath = new DOMXPath($doc);
$garbage = [];
foreach ($xpath->query('//p') as $entry) {
$garbage[] = $entry;
foreach ($entry->attributes as $attr) {
$garbage[] = $attr;
foreach ($attr->childNodes as $child) {
$garbage[] = $child;
}
}
}
@$doc->xinclude();
foreach ($garbage as $node) {
try {
var_dump($node->localName);
} catch (DOMException $e) {
echo $e->getMessage(), "\n";
}
}
?>
--EXPECT--
Invalid State Error
Invalid State Error
Invalid State Error
Invalid State Error
Invalid State Error
Invalid State Error
Invalid State Error