]> granicus.if.org Git - php/commitdiff
Fixed #75245 Don't set content of elements with only whitespaces
authorErik Lundin <erik@coretech.se>
Tue, 13 Aug 2019 20:50:37 +0000 (22:50 +0200)
committerJoe Watkins <krakjoe@php.net>
Wed, 2 Oct 2019 06:17:04 +0000 (08:17 +0200)
NEWS
ext/simplexml/simplexml.c
ext/simplexml/tests/bug39662.phpt
ext/simplexml/tests/bug75245.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index fccb03ca0908b067fcd9571eb7b6b9001227d70f..a7f668fa8c94d0549408a1ccd52515740fce3fca 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? ????, PHP 7.4.0RC4
 
+- SimpleXML:
+  . Fixed bug #75245 (Don't set content of elements with only whitespaces). 
+    (eriklundin)
 
 03 Oct 2019, PHP 7.4.0RC3
 
index 06c504884cf7cde3fc054407fadddf66d38b160f..2cdff0e648d77bd8d7f6252c367784c90a2966ae 100644 (file)
@@ -1197,7 +1197,7 @@ static HashTable *sxe_get_prop_hash(zval *object, int is_debug) /* {{{ */
                }
 
                while (node) {
-                       if (node->children != NULL || node->prev != NULL || node->next != NULL) {
+                       if (node->children != NULL || node->prev != NULL || node->next != NULL || xmlIsBlankNode(node)) {
                                SKIP_TEXT(node);
                        } else {
                                if (node->type == XML_TEXT_NODE) {
index b07e90064fcf405882dc78b30c63a09df53183d1..5dc2b99a924810183395108ff8aa095fb04bdafe 100644 (file)
@@ -19,17 +19,9 @@ var_dump($clone->asXML());
 echo "Done\n";
 ?>
 --EXPECTF--
-object(SimpleXMLElement)#%d (1) {
-  [0]=>
-  string(2) "
-
-"
+object(SimpleXMLElement)#%d (0) {
 }
-object(SimpleXMLElement)#%d (1) {
-  [0]=>
-  string(2) "
-
-"
+object(SimpleXMLElement)#%d (0) {
 }
 string(15) "<test>
 
diff --git a/ext/simplexml/tests/bug75245.phpt b/ext/simplexml/tests/bug75245.phpt
new file mode 100644 (file)
index 0000000..4a7a7ca
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+Bug #75245 Don't set content of elements with only whitespaces
+--SKIPIF--
+<?php
+if (!extension_loaded('simplexml')) die('skip simplexml not available');
+?>
+--FILE--
+<?php
+var_dump(simplexml_load_string('<test1><test2>    </test2><test3></test3></test1>'));
+?>
+===DONE===
+--EXPECT--
+object(SimpleXMLElement)#1 (2) {
+  ["test2"]=>
+  object(SimpleXMLElement)#2 (0) {
+  }
+  ["test3"]=>
+  object(SimpleXMLElement)#3 (0) {
+  }
+}
+===DONE===