1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.4'

* PHP-8.4:
  Fix xinclude destruction of live attributes
This commit is contained in:
Niels Dossche
2025-03-18 22:04:29 +01:00
2 changed files with 32 additions and 7 deletions

View File

@@ -1665,14 +1665,28 @@ PHP_METHOD(Dom_XMLDocument, saveXml)
}
/* }}} end dom_document_savexml */
static void dom_xinclude_strip_references_for_attributes(xmlNodePtr basep)
{
for (xmlAttrPtr prop = basep->properties; prop; prop = prop->next) {
php_libxml_node_free_resource((xmlNodePtr) prop);
for (xmlNodePtr child = prop->children; child; child = child->next) {
php_libxml_node_free_resource(child);
}
}
}
static void dom_xinclude_strip_references(xmlNodePtr basep)
{
php_libxml_node_free_resource(basep);
dom_xinclude_strip_references_for_attributes(basep);
xmlNodePtr current = basep->children;
while (current) {
php_libxml_node_free_resource(current);
if (current->type == XML_ELEMENT_NODE) {
dom_xinclude_strip_references_for_attributes(current);
}
current = php_dom_next_in_tree_order(current, basep);
}
}

View File

@@ -13,7 +13,7 @@ $doc->loadXML(<<<XML
</xi:include>
<xi:test xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="thisisnonexistent">
<p>garbage</p>
<p attr="foo" attr2="bar">garbage</p>
</xi:include>
</xi:test>
</root>
@@ -22,20 +22,31 @@ XML);
$xpath = new DOMXPath($doc);
$garbage = [];
foreach ($xpath->query('//p') as $entry)
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";
}
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