]> granicus.if.org Git - php/commitdiff
fix bug #49463 (setAttributeNS fails setting default namespace)
authorRob Richards <rrichards@php.net>
Fri, 15 Jan 2010 21:29:56 +0000 (21:29 +0000)
committerRob Richards <rrichards@php.net>
Fri, 15 Jan 2010 21:29:56 +0000 (21:29 +0000)
add test

NEWS
ext/dom/element.c
ext/dom/tests/bug49463.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 272ba2a2eb092d13e2a9e0d3d26c922f32877b90..80d5bf4449a06dab276d5613a1493a7783d9e846 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,7 @@ PHP                                                                        NEWS
   variable does not exist). (Ilia)
 - Fixed bug #50576 (XML_OPTION_SKIP_TAGSTART option has no effect). (Pierrick)
 - Fixed bug #49560 (oci8: using LOBs causes slow PHP shutdown). (Oracle Corp.)
+- 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)
index c4e192b37d8b54523395de2f4eed50474d67676d..785bf3faeba7efb6e350238f85cce06067aab5e3 100644 (file)
@@ -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 (file)
index 0000000..4f232e3
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Bug #49463 (setAttributeNS fails setting default namespace).
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+
+$doc = new DOMDocument('1.0', 'utf-8');
+$root = $doc->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--
+<?xml version="1.0" encoding="utf-8"?>
+<rdf:RDF xmlns:rdf="http://purl.org/rss/1.0/" xmlns="http://purl.org/rss/1.0/"/>