rrichards               Thu Sep 11 14:20:30 2008 UTC

  Added files:                 
    /php-src/ext/simplexml/tests        bug46047.phpt 

  Modified files:              
    /php-src/ext/simplexml      simplexml.c 
  Log:
  fix bug #46047 (SimpleXML converts empty nodes into object with nested array)
  add test
  
http://cvs.php.net/viewvc.cgi/php-src/ext/simplexml/simplexml.c?r1=1.260&r2=1.261&diff_format=u
Index: php-src/ext/simplexml/simplexml.c
diff -u php-src/ext/simplexml/simplexml.c:1.260 
php-src/ext/simplexml/simplexml.c:1.261
--- php-src/ext/simplexml/simplexml.c:1.260     Wed Sep 10 16:28:20 2008
+++ php-src/ext/simplexml/simplexml.c   Thu Sep 11 14:20:30 2008
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: simplexml.c,v 1.260 2008/09/10 16:28:20 rrichards Exp $ */
+/* $Id: simplexml.c,v 1.261 2008/09/11 14:20:30 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -1142,13 +1142,17 @@
                                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;
                                }
                        }
@@ -2640,7 +2644,7 @@
 {
        php_info_print_table_start();
        php_info_print_table_header(2, "Simplexml support", "enabled");
-       php_info_print_table_row(2, "Revision", "$Revision: 1.260 $");
+       php_info_print_table_row(2, "Revision", "$Revision: 1.261 $");
        php_info_print_table_row(2, "Schema support",
 #ifdef LIBXML_SCHEMAS_ENABLED
                "enabled");

http://cvs.php.net/viewvc.cgi/php-src/ext/simplexml/tests/bug46047.phpt?view=markup&rev=1.1
Index: php-src/ext/simplexml/tests/bug46047.phpt
+++ php-src/ext/simplexml/tests/bug46047.phpt
--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
        (
        )

)


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to