Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -1607,14 +1607,25 @@ 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);
}
}

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);
}
}
Expand Down
24 changes: 21 additions & 3 deletions ext/dom/tests/gh17847.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -22,15 +22,19 @@ 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;
}
}

@$doc->xinclude();

var_dump($garbage);
?>
--EXPECT--
array(3) {
array(5) {
[0]=>
object(DOMElement)#3 (1) {
["schemaTypeInfo"]=>
Expand All @@ -46,4 +50,18 @@ array(3) {
["schemaTypeInfo"]=>
NULL
}
[3]=>
object(DOMAttr)#10 (2) {
["specified"]=>
bool(true)
["schemaTypeInfo"]=>
NULL
}
[4]=>
object(DOMAttr)#11 (2) {
["specified"]=>
bool(true)
["schemaTypeInfo"]=>
NULL
}
}
Loading