]> granicus.if.org Git - php/commitdiff
MFB: fix bug #41257 (lookupNamespaceURI does not work as expected)
authorRob Richards <rrichards@php.net>
Fri, 4 May 2007 19:32:19 +0000 (19:32 +0000)
committerRob Richards <rrichards@php.net>
Fri, 4 May 2007 19:32:19 +0000 (19:32 +0000)
fix related issue in isDefaultNamespace
add test
reconcile namespaces when setting attribute in a new namespace

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

index 6ba7a95344bbbdead93bf548517677778d46f9c1..21d65c53f9dc6168ee35f6f83843f7096f94d54a 100644 (file)
@@ -709,6 +709,7 @@ PHP_FUNCTION(dom_element_set_attribute_ns)
                                        } else {
                                                nsptr = dom_get_ns(elemp, uri, &errorcode, prefix);
                                        }
+                                       xmlReconciliateNs(elemp->doc, elemp);
                                }
                        } else {
                                if (is_xmlns == 1) {
index 0a1ab0a5f2ea023cfd8f21904bcf97fccc7e0138..226badaa72137d6aa7fa1f1d3e2a7e77bf5335f0 100644 (file)
@@ -1587,8 +1587,11 @@ PHP_FUNCTION(dom_node_is_default_namespace)
        }
 
        DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
+       if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) {
+               nodep = xmlDocGetRootElement((xmlDocPtr) nodep);
+       }
 
-       if (uri_len > 0) {
+       if (nodep && uri_len > 0) {
                nsptr = xmlSearchNs(nodep->doc, nodep, NULL);
                if (nsptr && xmlStrEqual(nsptr->href, uri)) {
                        RETURN_TRUE;
@@ -1618,6 +1621,12 @@ PHP_FUNCTION(dom_node_lookup_namespace_uri)
        }
 
        DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
+       if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) {
+               nodep = xmlDocGetRootElement((xmlDocPtr) nodep);
+               if (nodep == NULL) {
+                       RETURN_NULL();
+               }
+       }
 
        nsptr = xmlSearchNs(nodep->doc, nodep, prefix);
        if (nsptr && nsptr->href != NULL) {
diff --git a/ext/dom/tests/bug41257.phpt b/ext/dom/tests/bug41257.phpt
new file mode 100644 (file)
index 0000000..58e6acf
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+Bug # 41257: (lookupNamespaceURI does not work as expected)
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+
+$doc = new DOMDocument();
+$doc->load(dirname(__FILE__)."/nsdoc.xml");
+
+$root = $doc->documentElement;
+
+$duri = $doc->lookupNamespaceURI("ns2")."\n";
+$euri = $root->lookupNamespaceURI("ns2")."\n";
+
+var_dump($duri == $euri);
+
+$dpref = $doc->lookupPrefix("http://ns2")."\n";
+$epref = $root->lookupPrefix("http://ns2")."\n";
+
+var_dump($dpref == $epref);
+
+$disdef = $doc->isDefaultNamespace("http://ns")."\n";
+$eisdef = $root->isDefaultNamespace("http://ns")."\n";
+
+var_dump($dpref === $epref);
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)