From: Pierre Joye Date: Wed, 3 Feb 2010 20:04:38 +0000 (+0000) Subject: - fix bug #49463 (setAttributeNS fails setting default namespace) X-Git-Tag: php-5.3.2RC2~75 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f37142f3375896edf67ec05259e524db3c210a57;p=php - fix bug #49463 (setAttributeNS fails setting default namespace) --- diff --git a/ext/dom/element.c b/ext/dom/element.c index c4e192b37d..785bf3faeb 100644 --- a/ext/dom/element.c +++ b/ext/dom/element.c @@ -777,9 +777,15 @@ PHP_FUNCTION(dom_element_set_attribute_ns) node_list_unlink(nodep->children TSRMLS_CC); } - if (xmlStrEqual((xmlChar *) prefix, (xmlChar *)"xmlns") && xmlStrEqual((xmlChar *) uri, (xmlChar *)DOM_XMLNS_NAMESPACE)) { + if ((xmlStrEqual((xmlChar *) prefix, (xmlChar *)"xmlns") || + (prefix == NULL && xmlStrEqual((xmlChar *) localname, (xmlChar *)"xmlns"))) && + xmlStrEqual((xmlChar *) uri, (xmlChar *)DOM_XMLNS_NAMESPACE)) { is_xmlns = 1; - nsptr = dom_get_nsdecl(elemp, (xmlChar *)localname); + if (prefix == NULL) { + nsptr = dom_get_nsdecl(elemp, NULL); + } else { + nsptr = dom_get_nsdecl(elemp, (xmlChar *)localname); + } } else { nsptr = xmlSearchNsByHref(elemp->doc, elemp, (xmlChar *)uri); if (nsptr && nsptr->prefix == NULL) { @@ -802,7 +808,12 @@ PHP_FUNCTION(dom_element_set_attribute_ns) if (nsptr == NULL) { if (prefix == NULL) { - errorcode = NAMESPACE_ERR; + if (is_xmlns == 1) { + xmlNewNs(elemp, (xmlChar *)value, NULL); + xmlReconciliateNs(elemp->doc, elemp); + } else { + errorcode = NAMESPACE_ERR; + } } else { if (is_xmlns == 1) { xmlNewNs(elemp, (xmlChar *)value, (xmlChar *)localname); diff --git a/ext/dom/tests/bug49463.phpt b/ext/dom/tests/bug49463.phpt new file mode 100644 index 0000000000..4f232e3b39 --- /dev/null +++ b/ext/dom/tests/bug49463.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #49463 (setAttributeNS fails setting default namespace). +--SKIPIF-- + +--FILE-- +createElementNS('http://purl.org/rss/1.0/','rdf:RDF'); +$doc->appendChild($root); +$root->setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns","http://purl.org/rss/1.0/" ); + +echo $doc->saveXML()."\n"; +?> +--EXPECT-- + +