summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Richards <rrichards@php.net>2007-11-28 10:43:02 +0000
committerRob Richards <rrichards@php.net>2007-11-28 10:43:02 +0000
commitb73a36a64f1a1586161cf84bfe9fb48a6666ce1f (patch)
tree884251877bfaa1d33500c9da6b2a2c41fdd9f467
parentc3e74e2d84a31b119f6ca6c6b8968bbcd3bfa677 (diff)
downloadphp-git-b73a36a64f1a1586161cf84bfe9fb48a6666ce1f.tar.gz
Fix bug #43364 (recursive xincludes don't remove internal nodes properly)
-rw-r--r--ext/dom/document.c4
-rw-r--r--ext/dom/tests/bug43364.phpt40
2 files changed, 44 insertions, 0 deletions
diff --git a/ext/dom/document.c b/ext/dom/document.c
index d3c05f192e..59fe5bd7d7 100644
--- a/ext/dom/document.c
+++ b/ext/dom/document.c
@@ -1767,6 +1767,10 @@ static void php_dom_remove_xinclude_nodes(xmlNodePtr cur TSRMLS_DC) {
/* XML_XINCLUDE_END node will be a sibling of XML_XINCLUDE_START */
while(cur && cur->type != XML_XINCLUDE_END) {
+ /* remove xinclude processing nodes from recursive xincludes */
+ if (cur->type == XML_ELEMENT_NODE) {
+ php_dom_remove_xinclude_nodes(cur->children TSRMLS_CC);
+ }
cur = cur->next;
}
diff --git a/ext/dom/tests/bug43364.phpt b/ext/dom/tests/bug43364.phpt
new file mode 100644
index 0000000000..0df581b7ac
--- /dev/null
+++ b/ext/dom/tests/bug43364.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Bug #43364 (recursive xincludes don't remove internal xml nodes properly)
+--FILE--
+<?php
+function loopElements($nodes)
+{
+ $count = 0;
+ foreach($nodes as $node) {
+ if($node instanceof DOMElement) {
+ $count++;
+ if($node->childNodes->length > 0) {
+ $count += loopElements($node->childNodes);
+ }
+ }
+ }
+ return $count;
+}
+
+$xml = <<<DOC
+<?xml version="1.0" encoding="UTF-8"?>
+<root xmlns:xi="http://www.w3.org/2001/XInclude">
+ <a>
+ <a_child1>ac1</a_child1>
+ <a_child2>ac2</a_child2>
+ </a>
+ <b><xi:include xpointer="xpointer(/root/a)" /></b>
+ <c><xi:include xpointer="xpointer(/root/b)" /></c>
+</root>
+DOC;
+
+$doc = new DomDocument();
+$doc->loadXml($xml);
+$doc->xinclude();
+
+$count = loopElements(array($doc->documentElement));
+
+var_dump($count);
+?>
+--EXPECT--
+int(13)