summaryrefslogtreecommitdiff
path: root/ext/simplexml
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-03-12 10:53:22 +0100
committerChristoph M. Becker <cmbecker69@gmx.de>2020-03-12 10:56:13 +0100
commit2b56735ea0772faeb635b22737e14115b9f1757c (patch)
treeb18cc030641350f8d79541b4f19f15f02244e238 /ext/simplexml
parentfee614f66bfb72384c7c6f316cad0c5c68fa9c0c (diff)
parent7c081db885756d7b176a55b90b8746f664d1e042 (diff)
downloadphp-git-2b56735ea0772faeb635b22737e14115b9f1757c.tar.gz
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #61597: SXE properties may lack attributes and content
Diffstat (limited to 'ext/simplexml')
-rw-r--r--ext/simplexml/simplexml.c2
-rw-r--r--ext/simplexml/tests/000.phpt32
-rw-r--r--ext/simplexml/tests/009b.phpt25
-rw-r--r--ext/simplexml/tests/bug51615.phpt26
-rw-r--r--ext/simplexml/tests/bug61597.phpt30
5 files changed, 108 insertions, 7 deletions
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index 2cdff0e648..0760598aff 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -981,7 +981,7 @@ static void _get_base_node_value(php_sxe_object *sxe_ref, xmlNodePtr node, zval
php_sxe_object *subnode;
xmlChar *contents;
- if (node->children && node->children->type == XML_TEXT_NODE && !xmlIsBlankNode(node->children)) {
+ if ((!node->properties || node->type == XML_ENTITY_DECL) && node->children && node->children->type == XML_TEXT_NODE && !xmlIsBlankNode(node->children)) {
contents = xmlNodeListGetString(node->doc, node->children, 1);
if (contents) {
ZVAL_STRING(value, (char *)contents);
diff --git a/ext/simplexml/tests/000.phpt b/ext/simplexml/tests/000.phpt
index d70a038ffa..0d4300e5ff 100644
--- a/ext/simplexml/tests/000.phpt
+++ b/ext/simplexml/tests/000.phpt
@@ -51,7 +51,37 @@ object(SimpleXMLElement)#%d (3) {
["elem1"]=>
array(2) {
[0]=>
- string(36) "There is some text.Here is some more"
+ object(SimpleXMLElement)#%d (3) {
+ ["@attributes"]=>
+ array(2) {
+ ["attr1"]=>
+ string(5) "first"
+ ["attr2"]=>
+ string(6) "second"
+ }
+ ["comment"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ ["elem2"]=>
+ object(SimpleXMLElement)#%d (2) {
+ ["@attributes"]=>
+ array(2) {
+ ["att25"]=>
+ string(2) "25"
+ ["att42"]=>
+ string(2) "42"
+ }
+ ["elem3"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["elem4"]=>
+ object(SimpleXMLElement)#%d (1) {
+ ["test"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ }
+ }
+ }
+ }
[1]=>
object(SimpleXMLElement)#%d (1) {
["@attributes"]=>
diff --git a/ext/simplexml/tests/009b.phpt b/ext/simplexml/tests/009b.phpt
index fd920e2e26..a8ca72c5ea 100644
--- a/ext/simplexml/tests/009b.phpt
+++ b/ext/simplexml/tests/009b.phpt
@@ -28,8 +28,29 @@ object(SimpleXMLElement)#%d (3) {
string(5) "elem1"
}
["elem1"]=>
- string(10) "Bla bla 1."
+ object(SimpleXMLElement)#%d (3) {
+ ["@attributes"]=>
+ array(1) {
+ ["attr1"]=>
+ string(5) "first"
+ }
+ ["comment"]=>
+ object(SimpleXMLElement)#%d (0) {
+ }
+ ["elem2"]=>
+ string(35) "
+ Here we have some text data.
+ "
+ }
["elem11"]=>
- string(10) "Bla bla 2."
+ object(SimpleXMLElement)#%d (2) {
+ ["@attributes"]=>
+ array(1) {
+ ["attr2"]=>
+ string(6) "second"
+ }
+ [0]=>
+ string(10) "Bla bla 2."
+ }
}
===DONE===
diff --git a/ext/simplexml/tests/bug51615.phpt b/ext/simplexml/tests/bug51615.phpt
index b935414b80..32af5f6ee4 100644
--- a/ext/simplexml/tests/bug51615.phpt
+++ b/ext/simplexml/tests/bug51615.phpt
@@ -22,7 +22,7 @@ foreach ($html->body->span as $obj) {
Warning: DOMDocument::loadHTML(): error parsing attribute name in Entity, line: 1 in %s on line %d
Warning: DOMDocument::loadHTML(): error parsing attribute name in Entity, line: 1 in %s on line %d
-object(SimpleXMLElement)#%d (3) {
+object(SimpleXMLElement)#5 (3) {
["@attributes"]=>
array(2) {
["title"]=>
@@ -31,9 +31,29 @@ object(SimpleXMLElement)#%d (3) {
string(0) ""
}
[0]=>
- string(1) "x"
+ object(SimpleXMLElement)#4 (2) {
+ ["@attributes"]=>
+ array(2) {
+ ["title"]=>
+ string(0) ""
+ ["y"]=>
+ string(0) ""
+ }
+ [0]=>
+ string(1) "x"
+ }
[1]=>
- string(1) "x"
+ object(SimpleXMLElement)#6 (2) {
+ ["@attributes"]=>
+ array(2) {
+ ["title"]=>
+ string(0) ""
+ ["z"]=>
+ string(0) ""
+ }
+ [0]=>
+ string(1) "x"
+ }
}
string(0) ""
string(0) ""
diff --git a/ext/simplexml/tests/bug61597.phpt b/ext/simplexml/tests/bug61597.phpt
new file mode 100644
index 0000000000..65fa6be772
--- /dev/null
+++ b/ext/simplexml/tests/bug61597.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Bug #61597 (SXE properties may lack attributes and content)
+--SKIPIF--
+<?php
+if (!extension_loaded('simplexml')) die('skip simplexml extension not available');
+?>
+--FILE--
+<?php
+$xml = <<<'EOX'
+<?xml version="1.0"?>
+<data>
+<datum file-key="8708124062829849862">corn</datum>
+</data>
+EOX;
+
+var_dump(simplexml_load_string($xml));
+?>
+--EXPECTF--
+object(SimpleXMLElement)#%d (1) {
+ ["datum"]=>
+ object(SimpleXMLElement)#%d (2) {
+ ["@attributes"]=>
+ array(1) {
+ ["file-key"]=>
+ string(19) "8708124062829849862"
+ }
+ [0]=>
+ string(4) "corn"
+ }
+}