mirror of
https://github.com/php/php-src.git
synced 2026-04-23 16:08:35 +02:00
MFH: fix bug #46047 (SimpleXML converts empty nodes into object with nested array)
add test
This commit is contained in:
@@ -1129,9 +1129,13 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
(
|
||||
)
|
||||
|
||||
)
|
||||
Reference in New Issue
Block a user