]> granicus.if.org Git - php/commitdiff
fix bug #46047 (SimpleXML converts empty nodes into object with nested array)
authorRob Richards <rrichards@php.net>
Thu, 11 Sep 2008 14:20:30 +0000 (14:20 +0000)
committerRob Richards <rrichards@php.net>
Thu, 11 Sep 2008 14:20:30 +0000 (14:20 +0000)
add test

ext/simplexml/simplexml.c
ext/simplexml/tests/bug46047.phpt [new file with mode: 0644]

index fc27d706bd13bbdb6a58d2e7e68a2d72ffa7c713..db1e840dc4ef7b081047bf4620ecb04a0377627d 100644 (file)
@@ -1142,13 +1142,17 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{
                                SKIP_TEXT(node);
                        } else {
                                if (node->type == XML_TEXT_NODE) {
-                                       xmlChar *tmp;
-
-                                       MAKE_STD_ZVAL(value);
-                                       tmp = xmlNodeListGetString(node->doc, node, 1);
-                                       ZVAL_XML_STRING(value, (char *)tmp, ZSTR_DUPLICATE);
-                                       xmlFree(tmp);
-                                       zend_hash_next_index_insert(rv, &value, sizeof(zval *), NULL);
+                                       const xmlChar *cur = node->content;
+                                       
+                                       if (*cur != 0) {
+                                               xmlChar *tmp;
+       
+                                               MAKE_STD_ZVAL(value);
+                                               tmp = xmlNodeListGetString(node->doc, node, 1);
+                                               ZVAL_XML_STRING(value, (char *)tmp, ZSTR_DUPLICATE);
+                                               xmlFree(tmp);
+                                               zend_hash_next_index_insert(rv, &value, sizeof(zval *), NULL);
+                                       }
                                        goto next_iter;
                                }
                        }
diff --git a/ext/simplexml/tests/bug46047.phpt b/ext/simplexml/tests/bug46047.phpt
new file mode 100644 (file)
index 0000000..37f31cd
--- /dev/null
@@ -0,0 +1,48 @@
+--TEST--
+Bug #46047 (SimpleXML converts empty nodes into object with nested array)
+--FILE--
+<?php
+$xml = new SimpleXMLElement('<foo><bar><![CDATA[]]></bar><baz/></foo>', 
+  LIBXML_NOCDATA);
+print_r($xml);
+
+$xml = new SimpleXMLElement('<foo><bar></bar><baz/></foo>');
+print_r($xml);
+
+$xml = new SimpleXMLElement('<foo><bar/><baz/></foo>');
+print_r($xml);
+?>
+--EXPECTF--
+SimpleXMLElement Object
+(
+    [bar] => SimpleXMLElement Object
+        (
+        )
+
+    [baz] => SimpleXMLElement Object
+        (
+        )
+
+)
+SimpleXMLElement Object
+(
+    [bar] => SimpleXMLElement Object
+        (
+        )
+
+    [baz] => SimpleXMLElement Object
+        (
+        )
+
+)
+SimpleXMLElement Object
+(
+    [bar] => SimpleXMLElement Object
+        (
+        )
+
+    [baz] => SimpleXMLElement Object
+        (
+        )
+
+)
\ No newline at end of file