]> granicus.if.org Git - php/commitdiff
Followup for bug #72971
authorNikita Popov <nikic@php.net>
Tue, 30 Aug 2016 10:43:41 +0000 (12:43 +0200)
committerNikita Popov <nikic@php.net>
Tue, 30 Aug 2016 10:53:50 +0000 (12:53 +0200)
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.

ext/simplexml/simplexml.c
ext/simplexml/tests/bug72971_2.phpt [new file with mode: 0644]

index 7c1e68787cf5fe2556798a47ff4be2bc08e4c971..1f70ddd684c8dfc607fb7c0465c64feddced5fa3 100644 (file)
@@ -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 (file)
index 0000000..aa6e094
--- /dev/null
@@ -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"
+}