summaryrefslogtreecommitdiff
path: root/ext/simplexml/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ext/simplexml/tests')
-rw-r--r--ext/simplexml/tests/bug42369.phpt25
-rw-r--r--ext/simplexml/tests/bug43221.phpt15
-rw-r--r--ext/simplexml/tests/bug44478.phpt24
3 files changed, 64 insertions, 0 deletions
diff --git a/ext/simplexml/tests/bug42369.phpt b/ext/simplexml/tests/bug42369.phpt
new file mode 100644
index 000000000..e5df81460
--- /dev/null
+++ b/ext/simplexml/tests/bug42369.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Bug #42369 (Implicit conversion to string leaks memory)
+--SKIPIF--
+<?php if (!extension_loaded('simplexml')) echo 'skip simplexml extension is not loaded'; >
+--FILE--
+<?php
+ $xml = '<?xml version="1.0" encoding="utf-8"?>';
+ $x = simplexml_load_string($xml . "<q><x>foo</x></q>");
+
+ echo 'explicit conversion' . PHP_EOL;
+ for ($i = 0; $i < 100000; $i++) {
+ md5(strval($x->x));
+ }
+
+ echo 'no conversion' . PHP_EOL;
+ for ($i = 0; $i < 100000; $i++) {
+ md5($x->x);
+ }
+
+ echo 'done' . PHP_EOL;
+?>
+--EXPECT--
+explicit conversion
+no conversion
+done \ No newline at end of file
diff --git a/ext/simplexml/tests/bug43221.phpt b/ext/simplexml/tests/bug43221.phpt
new file mode 100644
index 000000000..6973d091c
--- /dev/null
+++ b/ext/simplexml/tests/bug43221.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Bug #43221 (SimpleXML adding default namespace in addAttribute)
+--FILE--
+<?php
+$xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><root />');
+$n = $xml->addChild("node", "value");
+$n->addAttribute("a", "b");
+$n->addAttribute("c", "d", "http://bar.com");
+$n->addAttribute("foo:e", "f", "http://bar.com");
+print_r($xml->asXml());
+?>
+--EXPECTF--
+Warning: SimpleXMLElement::addAttribute(): Attribute requires prefix for namespace in %sbug43221.php on line %d
+<?xml version="1.0" encoding="utf-8"?>
+<root><node xmlns:foo="http://bar.com" a="b" foo:e="f">value</node></root> \ No newline at end of file
diff --git a/ext/simplexml/tests/bug44478.phpt b/ext/simplexml/tests/bug44478.phpt
new file mode 100644
index 000000000..5c21d75c8
--- /dev/null
+++ b/ext/simplexml/tests/bug44478.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Bug #44478 (Inconsistent behaviour when assigning new nodes)
+--FILE--
+<?php
+$xml_element = new simpleXMLElement('<root></root>');
+$xml_element->node1 = 'a &#38; b';
+print $xml_element->node1."\n";
+$xml_element->node1 = 'a &#38; b';
+print $xml_element->node1."\n";
+$xml_element->addChild('node2','a &#38; b');
+print $xml_element->node2."\n";
+$xml_element->node2 = 'a & b';
+print $xml_element->node2."\n";
+
+print $xml_element->asXML();
+
+?>
+--EXPECTF--
+a &#38; b
+a &#38; b
+a & b
+a & b
+<?xml version="1.0"?>
+<root><node1>a &amp;#38; b</node1><node2>a &amp; b</node2></root>