Skip to content

Commit a0beddf

Browse files
committed
Fixed bug #66084 simplexml_load_string() mangles empty node name
1 parent 7e5de3a commit a0beddf

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ PHP NEWS
1616
. Fixed bug #66987i (Memory corruption in fileinfo ext / bigendian).
1717
(Remi)
1818

19+
- SimpleXML:
20+
. Fixed bug #66084 (simplexml_load_string() mangles empty node name)
21+
(Anatol)
22+
1923
- XSL:
2024
. Fixed bug #53965 (<xsl:include> cannot find files with relative paths
2125
when loaded with "file://"). (Anatol)

ext/simplexml/simplexml.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{
11291129
node = NULL;
11301130
} else if (sxe->iter.type != SXE_ITER_CHILD) {
11311131

1132-
if ( !node->children || !node->parent || node->children->next || node->children->children || node->parent->children == node->parent->last ) {
1132+
if ( !node->children || !node->parent || !node->next || node->children->next || node->children->children || node->parent->children == node->parent->last ) {
11331133
node = node->children;
11341134
} else {
11351135
iter_data = sxe->iter.data;

ext/simplexml/tests/bug66084_0.phpt

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
--TEST--
2+
Bug #66084 simplexml_load_string() mangles empty node name, var_dump variant
3+
--SKIPIF--
4+
<?php if (!extension_loaded("simplexml")) print "skip simplexml not available"; ?>
5+
--FILE--
6+
<?php
7+
echo var_dump(simplexml_load_string('<a><b/><c><x/></c></a>')), "\n";
8+
echo var_dump(simplexml_load_string('<a><b/><d/><c><x/></c></a>')), "\n";
9+
echo var_dump(simplexml_load_string('<a><b/><c><d/><x/></c></a>')), "\n";
10+
echo var_dump(simplexml_load_string('<a><b/><c><d><x/></d></c></a>')), "\n";
11+
?>
12+
--EXPECT--
13+
object(SimpleXMLElement)#1 (2) {
14+
["b"]=>
15+
object(SimpleXMLElement)#2 (0) {
16+
}
17+
["c"]=>
18+
object(SimpleXMLElement)#3 (1) {
19+
["x"]=>
20+
object(SimpleXMLElement)#4 (0) {
21+
}
22+
}
23+
}
24+
25+
object(SimpleXMLElement)#1 (3) {
26+
["b"]=>
27+
object(SimpleXMLElement)#3 (0) {
28+
}
29+
["d"]=>
30+
object(SimpleXMLElement)#2 (0) {
31+
}
32+
["c"]=>
33+
object(SimpleXMLElement)#4 (1) {
34+
["x"]=>
35+
object(SimpleXMLElement)#5 (0) {
36+
}
37+
}
38+
}
39+
40+
object(SimpleXMLElement)#1 (2) {
41+
["b"]=>
42+
object(SimpleXMLElement)#4 (0) {
43+
}
44+
["c"]=>
45+
object(SimpleXMLElement)#2 (2) {
46+
["d"]=>
47+
object(SimpleXMLElement)#3 (0) {
48+
}
49+
["x"]=>
50+
object(SimpleXMLElement)#5 (0) {
51+
}
52+
}
53+
}
54+
55+
object(SimpleXMLElement)#1 (2) {
56+
["b"]=>
57+
object(SimpleXMLElement)#2 (0) {
58+
}
59+
["c"]=>
60+
object(SimpleXMLElement)#4 (1) {
61+
["d"]=>
62+
object(SimpleXMLElement)#5 (1) {
63+
["x"]=>
64+
object(SimpleXMLElement)#3 (0) {
65+
}
66+
}
67+
}
68+
}

ext/simplexml/tests/bug66084_1.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #66084 simplexml_load_string() mangles empty node name, json variant
3+
--SKIPIF--
4+
<?php if (!extension_loaded("simplexml")) print "skip simplexml not available"; ?>
5+
<?php if (!extension_loaded("json")) print "skip json not available"; ?>
6+
--FILE--
7+
<?php
8+
echo json_encode(simplexml_load_string('<a><b/><c><x/></c></a>')), "\n";
9+
echo json_encode(simplexml_load_string('<a><b/><d/><c><x/></c></a>')), "\n";
10+
echo json_encode(simplexml_load_string('<a><b/><c><d/><x/></c></a>')), "\n";
11+
echo json_encode(simplexml_load_string('<a><b/><c><d><x/></d></c></a>')), "\n";
12+
?>
13+
--EXPECT--
14+
{"b":{},"c":{"x":{}}}
15+
{"b":{},"d":{},"c":{"x":{}}}
16+
{"b":{},"c":{"d":{},"x":{}}}
17+
{"b":{},"c":{"d":{"x":{}}}}

0 commit comments

Comments
 (0)