From: Rob Richards Date: Mon, 12 Nov 2007 18:58:01 +0000 (+0000) Subject: fix bug #43221 (SimpleXML adding default namespace in addAttribute) X-Git-Tag: RELEASE_2_0_0a1~1384 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=62d03825b26077337294a97db17b693d2ce5dfbe;p=php fix bug #43221 (SimpleXML adding default namespace in addAttribute) add test --- diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 8b054673ef..9840130af7 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -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 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