]> granicus.if.org Git - php/commitdiff
MFH: Fix bug #43364 (recursive xincludes don't remove internal nodes properly)
authorRob Richards <rrichards@php.net>
Wed, 28 Nov 2007 10:44:21 +0000 (10:44 +0000)
committerRob Richards <rrichards@php.net>
Wed, 28 Nov 2007 10:44:21 +0000 (10:44 +0000)
add test

ext/dom/document.c
ext/dom/tests/bug43364.phpt [new file with mode: 0644]

index acfcc71f1dd0bab6a3a22b6ea14d21d1f0e1224c..490e56e359e56274617af860c1586b9f818a3d0d 100644 (file)
@@ -1737,6 +1737,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 (file)
index 0000000..0df581b
--- /dev/null
@@ -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)