Skip to content

Commit b450a9c

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix xinclude destruction of live attributes
2 parents 6329248 + 2c45d67 commit b450a9c

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

ext/dom/document.c

+14
Original file line numberDiff line numberDiff line change
@@ -1665,14 +1665,28 @@ PHP_METHOD(Dom_XMLDocument, saveXml)
16651665
}
16661666
/* }}} end dom_document_savexml */
16671667

1668+
static void dom_xinclude_strip_references_for_attributes(xmlNodePtr basep)
1669+
{
1670+
for (xmlAttrPtr prop = basep->properties; prop; prop = prop->next) {
1671+
php_libxml_node_free_resource((xmlNodePtr) prop);
1672+
for (xmlNodePtr child = prop->children; child; child = child->next) {
1673+
php_libxml_node_free_resource(child);
1674+
}
1675+
}
1676+
}
1677+
16681678
static void dom_xinclude_strip_references(xmlNodePtr basep)
16691679
{
16701680
php_libxml_node_free_resource(basep);
1681+
dom_xinclude_strip_references_for_attributes(basep);
16711682

16721683
xmlNodePtr current = basep->children;
16731684

16741685
while (current) {
16751686
php_libxml_node_free_resource(current);
1687+
if (current->type == XML_ELEMENT_NODE) {
1688+
dom_xinclude_strip_references_for_attributes(current);
1689+
}
16761690
current = php_dom_next_in_tree_order(current, basep);
16771691
}
16781692
}

ext/dom/tests/gh17847.phpt

+18-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $doc->loadXML(<<<XML
1313
</xi:include>
1414
<xi:test xmlns:xi="http://www.w3.org/2001/XInclude">
1515
<xi:include href="thisisnonexistent">
16-
<p>garbage</p>
16+
<p attr="foo" attr2="bar">garbage</p>
1717
</xi:include>
1818
</xi:test>
1919
</root>
@@ -22,20 +22,31 @@ XML);
2222
$xpath = new DOMXPath($doc);
2323

2424
$garbage = [];
25-
foreach ($xpath->query('//p') as $entry)
25+
foreach ($xpath->query('//p') as $entry) {
2626
$garbage[] = $entry;
27+
foreach ($entry->attributes as $attr) {
28+
$garbage[] = $attr;
29+
foreach ($attr->childNodes as $child) {
30+
$garbage[] = $child;
31+
}
32+
}
33+
}
2734

2835
@$doc->xinclude();
2936

3037
foreach ($garbage as $node) {
31-
try {
32-
var_dump($node->localName);
33-
} catch (DOMException $e) {
34-
echo $e->getMessage(), "\n";
35-
}
38+
try {
39+
var_dump($node->localName);
40+
} catch (DOMException $e) {
41+
echo $e->getMessage(), "\n";
42+
}
3643
}
3744
?>
3845
--EXPECT--
3946
Invalid State Error
4047
Invalid State Error
4148
Invalid State Error
49+
Invalid State Error
50+
Invalid State Error
51+
Invalid State Error
52+
Invalid State Error

0 commit comments

Comments
 (0)