Skip to content

Commit b73a36a

Browse files
author
Rob Richards
committed
Fix bug #43364 (recursive xincludes don't remove internal nodes properly)
1 parent c3e74e2 commit b73a36a

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

ext/dom/document.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,10 @@ static void php_dom_remove_xinclude_nodes(xmlNodePtr cur TSRMLS_DC) {
17671767

17681768
/* XML_XINCLUDE_END node will be a sibling of XML_XINCLUDE_START */
17691769
while(cur && cur->type != XML_XINCLUDE_END) {
1770+
/* remove xinclude processing nodes from recursive xincludes */
1771+
if (cur->type == XML_ELEMENT_NODE) {
1772+
php_dom_remove_xinclude_nodes(cur->children TSRMLS_CC);
1773+
}
17701774
cur = cur->next;
17711775
}
17721776

ext/dom/tests/bug43364.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Bug #43364 (recursive xincludes don't remove internal xml nodes properly)
3+
--FILE--
4+
<?php
5+
function loopElements($nodes)
6+
{
7+
$count = 0;
8+
foreach($nodes as $node) {
9+
if($node instanceof DOMElement) {
10+
$count++;
11+
if($node->childNodes->length > 0) {
12+
$count += loopElements($node->childNodes);
13+
}
14+
}
15+
}
16+
return $count;
17+
}
18+
19+
$xml = <<<DOC
20+
<?xml version="1.0" encoding="UTF-8"?>
21+
<root xmlns:xi="http://www.w3.org/2001/XInclude">
22+
<a>
23+
<a_child1>ac1</a_child1>
24+
<a_child2>ac2</a_child2>
25+
</a>
26+
<b><xi:include xpointer="xpointer(/root/a)" /></b>
27+
<c><xi:include xpointer="xpointer(/root/b)" /></c>
28+
</root>
29+
DOC;
30+
31+
$doc = new DomDocument();
32+
$doc->loadXml($xml);
33+
$doc->xinclude();
34+
35+
$count = loopElements(array($doc->documentElement));
36+
37+
var_dump($count);
38+
?>
39+
--EXPECT--
40+
int(13)

0 commit comments

Comments
 (0)