]> granicus.if.org Git - php/commitdiff
fix bug #43221 (SimpleXML adding default namespace in addAttribute)
authorRob Richards <rrichards@php.net>
Mon, 12 Nov 2007 18:58:01 +0000 (18:58 +0000)
committerRob Richards <rrichards@php.net>
Mon, 12 Nov 2007 18:58:01 +0000 (18:58 +0000)
add test

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

index 8b054673ef93f7a78e2ca45150d41aca1d4bbb6b..9840130af7d920246fe63d1c02ffe32728edce17 100644 (file)
@@ -1697,6 +1697,13 @@ SXE_METHOD(addAttribute)
 
        localname = xmlSplitQName2((xmlChar *)qname, &prefix);
        if (localname == NULL) {
+               if (nsuri_len > 0) {
+                       if (prefix != NULL) {
+                               xmlFree(prefix);
+                       }
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute requires prefix for namespace");
+                       return;
+               }
                localname = xmlStrdup((xmlChar *)qname);
        }
 
diff --git a/ext/simplexml/tests/bug43221.phpt b/ext/simplexml/tests/bug43221.phpt
new file mode 100644 (file)
index 0000000..6973d09
--- /dev/null
@@ -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