Skip to content

Commit 208e348

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #61597: SXE properties may lack attributes and content
2 parents 1072658 + 2b56735 commit 208e348

File tree

5 files changed

+108
-7
lines changed

5 files changed

+108
-7
lines changed

ext/simplexml/simplexml.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ static void _get_base_node_value(php_sxe_object *sxe_ref, xmlNodePtr node, zval
990990
php_sxe_object *subnode;
991991
xmlChar *contents;
992992

993-
if (node->children && node->children->type == XML_TEXT_NODE && !xmlIsBlankNode(node->children)) {
993+
if ((!node->properties || node->type == XML_ENTITY_DECL) && node->children && node->children->type == XML_TEXT_NODE && !xmlIsBlankNode(node->children)) {
994994
contents = xmlNodeListGetString(node->doc, node->children, 1);
995995
if (contents) {
996996
ZVAL_STRING(value, (char *)contents);

ext/simplexml/tests/000.phpt

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

ext/simplexml/tests/009b.phpt

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

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)