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

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

index 54a1d8f8aab285d90a10588b1f57d6f91cdec1a6..116b140b4b05c895369f8a3604a15ff1d6fc0dee 100644 (file)
@@ -1101,9 +1101,13 @@ static HashTable * sxe_properties_get(zval *object TSRMLS_DC)
                                SKIP_TEXT(node);
                        } else {
                                if (node->type == XML_TEXT_NODE) {
-                                       MAKE_STD_ZVAL(value);
-                                       ZVAL_STRING(value, sxe_xmlNodeListGetString(node->doc, node, 1), 0);
-                                       zend_hash_next_index_insert(rv, &value, sizeof(zval *), NULL);
+                                       const xmlChar *cur = node->content;
+                                       
+                                       if (*cur != 0) {
+                                               MAKE_STD_ZVAL(value);
+                                               ZVAL_STRING(value, sxe_xmlNodeListGetString(node->doc, node, 1), 0);
+                                               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