1
0
mirror of https://github.com/php/php-src.git synced 2026-04-25 00:48:25 +02:00

fix bug #46047 (SimpleXML converts empty nodes into object with nested array)

add test
This commit is contained in:
Rob Richards
2008-09-11 14:20:30 +00:00
parent bdb50267f7
commit 5f50350ca9
2 changed files with 59 additions and 7 deletions
+11 -7
View 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;
}
}
+48
View File
@@ -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
(
)
)