From: Rob Richards Date: Fri, 4 May 2007 19:32:19 +0000 (+0000) Subject: MFB: fix bug #41257 (lookupNamespaceURI does not work as expected) X-Git-Tag: RELEASE_1_2_0~161 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=45d4f66b248dafcc94c563cbf0ad21d5965a9119;p=php MFB: fix bug #41257 (lookupNamespaceURI does not work as expected) fix related issue in isDefaultNamespace add test reconcile namespaces when setting attribute in a new namespace --- diff --git a/ext/dom/element.c b/ext/dom/element.c index 6ba7a95344..21d65c53f9 100644 --- a/ext/dom/element.c +++ b/ext/dom/element.c @@ -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) { diff --git a/ext/dom/node.c b/ext/dom/node.c index 0a1ab0a5f2..226badaa72 100644 --- a/ext/dom/node.c +++ b/ext/dom/node.c @@ -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 index 0000000000..58e6acfd59 --- /dev/null +++ b/ext/dom/tests/bug41257.phpt @@ -0,0 +1,31 @@ +--TEST-- +Bug # 41257: (lookupNamespaceURI does not work as expected) +--SKIPIF-- + +--FILE-- +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)