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

Fix xinclude destruction of live attributes

Follow-up for GH-17847 but now for attributes.

Closes GH-18100.
This commit is contained in:
Niels Dossche
2025-03-17 20:05:43 +01:00
parent c531f3d79b
commit d9329b1522
3 changed files with 45 additions and 3 deletions

1
NEWS
View File

@@ -10,6 +10,7 @@ PHP NEWS
- DOM:
. Fix weird unpack behaviour in DOM. (nielsdos)
. Fix xinclude destruction of live attributes. (nielsdos)
- GD:
. Fixed bug GH-17984 (calls with arguments as array with references).

View File

@@ -1607,14 +1607,28 @@ static zend_always_inline xmlNodePtr php_dom_next_in_tree_order(const xmlNode *n
}
}
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,15 +22,22 @@ 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();
var_dump($garbage);
?>
--EXPECT--
array(3) {
array(7) {
[0]=>
object(DOMElement)#3 (1) {
["schemaTypeInfo"]=>
@@ -46,4 +53,24 @@ array(3) {
["schemaTypeInfo"]=>
NULL
}
[3]=>
object(DOMAttr)#10 (2) {
["specified"]=>
bool(true)
["schemaTypeInfo"]=>
NULL
}
[4]=>
object(DOMText)#13 (0) {
}
[5]=>
object(DOMAttr)#12 (2) {
["specified"]=>
bool(true)
["schemaTypeInfo"]=>
NULL
}
[6]=>
object(DOMText)#15 (0) {
}
}