com php-src: Followup for bug #72971: ext/simplexml/simplexml.c ext/simplexml/tests/bug72971_2.phpt
| From: | Nikita Popov | Date: | Tue, 30 Aug 2016 10:53:50 +0000 |
| Subject: | com php-src: Followup for bug #72971: ext/simplexml/simplexml.c ext/simplexml/tests/bug72971_2.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94151@lists.php.net to get a copy of this message | ||
Commit: 6adb7e0b7a1d57407f5267293b8b8d63f74b60a7
Author: Nikita Popov <nikic@php.net> Tue, 30 Aug 2016 12:43:41 +0200
Parents: 07cc6a6ba2d8cebe2b375353491a26953b250149
Branches: PHP-7.0 PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=6adb7e0b7a1d57407f5267293b8b8d63f74b60a7
Log:
Followup for bug #72971
Property writes did not respect the namespace either. This is an
incomplete fix in that it only handles the case where an existing
child element is modified, not when a new one is created.
Bugs:
https://bugs.php.net/72971
Changed paths:
M ext/simplexml/simplexml.c
A ext/simplexml/tests/bug72971_2.phpt
Diff:
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index 7c1e687..1f70ddd 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -607,7 +607,7 @@ long_dim:
while (node) {
SKIP_TEXT(node);
- if (!xmlStrcmp(node->name, (xmlChar *)Z_STRVAL_P(member))) {
+ if (!xmlStrcmp(node->name, (xmlChar *)Z_STRVAL_P(member)) && match_ns(sxe, node,
sxe->iter.nsprefix, sxe->iter.isprefix)) {
newnode = node;
++counter;
}
diff --git a/ext/simplexml/tests/bug72971_2.phpt b/ext/simplexml/tests/bug72971_2.phpt
new file mode 100644
index 0000000..aa6e094
--- /dev/null
+++ b/ext/simplexml/tests/bug72971_2..phpt
@@ -0,0 +1,35 @@
+--TEST--
+Bug #72971 (2): SimpleXML property write does not respect namespace
+--SKIPIF--
+<?php if (!extension_loaded("simplexml")) print "skip simplexml extension is not
loaded"; ?>
+--FILE--
+<?php
+
+$xml = new SimpleXMLElement('<root
xmlns:ns="ns"><foo>bar</foo><ns:foo>ns:bar</ns:foo></root>');
+
+$xml->foo = 'new-bar';
+var_dump($xml->foo);
+var_dump($xml->children('ns')->foo);
+
+$xml->children('ns')->foo = 'ns:new-bar';
+var_dump($xml->foo);
+var_dump($xml->children('ns')->foo);
+
+?>
+--EXPECT--
+object(SimpleXMLElement)#2 (1) {
+ [0]=>
+ string(7) "new-bar"
+}
+object(SimpleXMLElement)#3 (1) {
+ [0]=>
+ string(6) "ns:bar"
+}
+object(SimpleXMLElement)#3 (1) {
+ [0]=>
+ string(7) "new-bar"
+}
+object(SimpleXMLElement)#2 (1) {
+ [0]=>
+ string(10) "ns:new-bar"
+}