From: Rob Richards Date: Mon, 12 Nov 2007 18:58:48 +0000 (+0000) Subject: MFH: fix bug #43221 (SimpleXML adding default namespace in addAttribute) X-Git-Tag: RELEASE_1_3_1~657 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5d10360d5a17240eec5dd54c678294ed5a3d92c2;p=php MFH: fix bug #43221 (SimpleXML adding default namespace in addAttribute) add test --- diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 734c593df8..e1fac8a0a0 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1655,6 +1655,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 index 0000000000..6973d091c7 --- /dev/null +++ b/ext/simplexml/tests/bug43221.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #43221 (SimpleXML adding default namespace in addAttribute) +--FILE-- +'); +$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 + +value \ No newline at end of file