From 45bce8f3d53b1645ad9f6cb070a8b8210ee4c120 Mon Sep 17 00:00:00 2001 From: Rob Richards Date: Fri, 15 Jan 2010 21:29:56 +0000 Subject: [PATCH] fix bug #49463 (setAttributeNS fails setting default namespace) add test --- NEWS | 1 + ext/dom/element.c | 21 ++++++++++++++++----- ext/dom/tests/bug49463.phpt | 17 +++++++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 ext/dom/tests/bug49463.phpt diff --git a/NEWS b/NEWS index 14fbf44e69..76a5a7f583 100644 --- a/NEWS +++ b/NEWS @@ -36,6 +36,7 @@ PHP NEWS - Fixed bug #50394 (Reference argument converted to value in __call). (Stas) - Fixed bug #49851 (http wrapper breaks on 1024 char long headers). (Ilia) - Fixed bug #49600 (imageTTFText text shifted right). (Takeshi Abe) +- Fixed bug #49463 (setAttributeNS fails setting default namespace). (Rob) - Fixed bug #48590 (SoapClient does not honor max_redirects). (Sriram) - Fixed bug #48190 (Content-type parameter "boundary" is not case-insensitive in HTTP uploads). (Ilia) diff --git a/ext/dom/element.c b/ext/dom/element.c index 88d4777eb8..9e336655f4 100644 --- a/ext/dom/element.c +++ b/ext/dom/element.c @@ -792,11 +792,17 @@ PHP_FUNCTION(dom_element_set_attribute_ns) node_list_unlink(nodep->children TSRMLS_CC); } - if (xmlStrEqual((xmlChar *) prefix,"xmlns") && xmlStrEqual((xmlChar *) uri, 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, localname); + if (prefix == NULL) { + nsptr = dom_get_nsdecl(elemp, NULL); + } else { + nsptr = dom_get_nsdecl(elemp, (xmlChar *)localname); + } } else { - nsptr = xmlSearchNsByHref(elemp->doc, elemp, uri); + nsptr = xmlSearchNsByHref(elemp->doc, elemp, (xmlChar *)uri); if (nsptr && nsptr->prefix == NULL) { xmlNsPtr tmpnsptr; @@ -817,10 +823,15 @@ 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, value, localname); + xmlNewNs(elemp, (xmlChar *)value, (xmlChar *)localname); } else { nsptr = dom_get_ns(elemp, uri, &errorcode, prefix); } 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-- + + -- 2.50.1