]> granicus.if.org Git - php/commitdiff
Fix #61597: SXE properties may lack attributes and content
authorChristoph M. Becker <cmbecker69@gmx.de>
Sat, 7 Mar 2020 10:20:06 +0000 (11:20 +0100)
committerChristoph M. Becker <cmbecker69@gmx.de>
Thu, 12 Mar 2020 09:52:28 +0000 (10:52 +0100)
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.

NEWS
ext/simplexml/simplexml.c
ext/simplexml/tests/000.phpt
ext/simplexml/tests/009b.phpt
ext/simplexml/tests/bug51615.phpt
ext/simplexml/tests/bug61597.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 7d61149ac01e8304f31c9656b511babb153753dc..8fd4c708fda2e02ec667ee397252284c676285f9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,9 @@ PHP                                                                        NEWS
   . Fixed bug #79364 (When copy empty array, next key is unspecified). (cmb)
   . Fixed bug #78210 (Invalid pointer address). (cmb, Nikita)
 
+- SimpleXML:
+  . Fixed bug #61597 (SXE properties may lack attributes and content). (cmb)
+
 - Spl:
   . Fixed bug #75673 (SplStack::unserialize() behavior). (cmb)
 
index ab394b5c83b76659991e3963df5568c3f442b716..a27a9849a318e8c8eaa3d70db81af70aa8af55e7 100644 (file)
@@ -964,7 +964,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);
index 8a35fc9ba353ce52f7529a6bc8527706af172a4e..dde32d8eaa093e55c46d8823a98d3c88ff71daa8 100644 (file)
@@ -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"]=>
index fd920e2e265b29720e24579ff216b8a4d12e7d20..a8ca72c5eaa725686d9ed42a635771ef1878ad00 100644 (file)
@@ -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===
index b935414b80daf0e95f9674054a5fd2366c23aff5..32af5f6ee4021df42c4a877e4ada606d38db3be7 100644 (file)
@@ -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 (file)
index 0000000..65fa6be
--- /dev/null
@@ -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"
+  }
+}