Skip to content

Commit 7c081db

Browse files
committed
Fix #61597: SXE properties may lack attributes and content
We must not treat a node as string if it has attributes, unless it is an entity declaration which is always treated as string by simplexml.
1 parent 53797c2 commit 7c081db

File tree

6 files changed

+111
-7
lines changed

6 files changed

+111
-7
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ PHP NEWS
66
. Fixed bug #79364 (When copy empty array, next key is unspecified). (cmb)
77
. Fixed bug #78210 (Invalid pointer address). (cmb, Nikita)
88

9+
- SimpleXML:
10+
. Fixed bug #61597 (SXE properties may lack attributes and content). (cmb)
11+
912
- Spl:
1013
. Fixed bug #75673 (SplStack::unserialize() behavior). (cmb)
1114

ext/simplexml/simplexml.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ static void _get_base_node_value(php_sxe_object *sxe_ref, xmlNodePtr node, zval
964964
php_sxe_object *subnode;
965965
xmlChar *contents;
966966

967-
if (node->children && node->children->type == XML_TEXT_NODE && !xmlIsBlankNode(node->children)) {
967+
if ((!node->properties || node->type == XML_ENTITY_DECL) && node->children && node->children->type == XML_TEXT_NODE && !xmlIsBlankNode(node->children)) {
968968
contents = xmlNodeListGetString(node->doc, node->children, 1);
969969
if (contents) {
970970
ZVAL_STRING(value, (char *)contents);

ext/simplexml/tests/000.phpt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,37 @@ object(SimpleXMLElement)#%d (3) {
5151
["elem1"]=>
5252
array(2) {
5353
[0]=>
54-
string(36) "There is some text.Here is some more"
54+
object(SimpleXMLElement)#%d (3) {
55+
["@attributes"]=>
56+
array(2) {
57+
["attr1"]=>
58+
string(5) "first"
59+
["attr2"]=>
60+
string(6) "second"
61+
}
62+
["comment"]=>
63+
object(SimpleXMLElement)#%d (0) {
64+
}
65+
["elem2"]=>
66+
object(SimpleXMLElement)#%d (2) {
67+
["@attributes"]=>
68+
array(2) {
69+
["att25"]=>
70+
string(2) "25"
71+
["att42"]=>
72+
string(2) "42"
73+
}
74+
["elem3"]=>
75+
object(SimpleXMLElement)#%d (1) {
76+
["elem4"]=>
77+
object(SimpleXMLElement)#%d (1) {
78+
["test"]=>
79+
object(SimpleXMLElement)#%d (0) {
80+
}
81+
}
82+
}
83+
}
84+
}
5585
[1]=>
5686
object(SimpleXMLElement)#%d (1) {
5787
["@attributes"]=>

ext/simplexml/tests/009b.phpt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,29 @@ object(SimpleXMLElement)#%d (3) {
2828
string(5) "elem1"
2929
}
3030
["elem1"]=>
31-
string(10) "Bla bla 1."
31+
object(SimpleXMLElement)#%d (3) {
32+
["@attributes"]=>
33+
array(1) {
34+
["attr1"]=>
35+
string(5) "first"
36+
}
37+
["comment"]=>
38+
object(SimpleXMLElement)#%d (0) {
39+
}
40+
["elem2"]=>
41+
string(35) "
42+
Here we have some text data.
43+
"
44+
}
3245
["elem11"]=>
33-
string(10) "Bla bla 2."
46+
object(SimpleXMLElement)#%d (2) {
47+
["@attributes"]=>
48+
array(1) {
49+
["attr2"]=>
50+
string(6) "second"
51+
}
52+
[0]=>
53+
string(10) "Bla bla 2."
54+
}
3455
}
3556
===DONE===

ext/simplexml/tests/bug51615.phpt

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ foreach ($html->body->span as $obj) {
2222
Warning: DOMDocument::loadHTML(): error parsing attribute name in Entity, line: 1 in %s on line %d
2323

2424
Warning: DOMDocument::loadHTML(): error parsing attribute name in Entity, line: 1 in %s on line %d
25-
object(SimpleXMLElement)#%d (3) {
25+
object(SimpleXMLElement)#5 (3) {
2626
["@attributes"]=>
2727
array(2) {
2828
["title"]=>
@@ -31,9 +31,29 @@ object(SimpleXMLElement)#%d (3) {
3131
string(0) ""
3232
}
3333
[0]=>
34-
string(1) "x"
34+
object(SimpleXMLElement)#4 (2) {
35+
["@attributes"]=>
36+
array(2) {
37+
["title"]=>
38+
string(0) ""
39+
["y"]=>
40+
string(0) ""
41+
}
42+
[0]=>
43+
string(1) "x"
44+
}
3545
[1]=>
36-
string(1) "x"
46+
object(SimpleXMLElement)#6 (2) {
47+
["@attributes"]=>
48+
array(2) {
49+
["title"]=>
50+
string(0) ""
51+
["z"]=>
52+
string(0) ""
53+
}
54+
[0]=>
55+
string(1) "x"
56+
}
3757
}
3858
string(0) ""
3959
string(0) ""

ext/simplexml/tests/bug61597.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Bug #61597 (SXE properties may lack attributes and content)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('simplexml')) die('skip simplexml extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$xml = <<<'EOX'
10+
<?xml version="1.0"?>
11+
<data>
12+
<datum file-key="8708124062829849862">corn</datum>
13+
</data>
14+
EOX;
15+
16+
var_dump(simplexml_load_string($xml));
17+
?>
18+
--EXPECTF--
19+
object(SimpleXMLElement)#%d (1) {
20+
["datum"]=>
21+
object(SimpleXMLElement)#%d (2) {
22+
["@attributes"]=>
23+
array(1) {
24+
["file-key"]=>
25+
string(19) "8708124062829849862"
26+
}
27+
[0]=>
28+
string(4) "corn"
29+
}
30+
}

0 commit comments

Comments
 (0)