From: Rob Richards Date: Mon, 29 Sep 2008 16:52:03 +0000 (+0000) Subject: fix bug #46185 (importNode changes the namespace of an XML element) X-Git-Tag: BEFORE_HEAD_NS_CHANGE~321 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=00b84bb1fd26b3e958cd196ebaf5942a074c16f8;p=php fix bug #46185 (importNode changes the namespace of an XML element) add test --- diff --git a/ext/dom/node.c b/ext/dom/node.c index fa7ce57770..c067955a7c 100644 --- a/ext/dom/node.c +++ b/ext/dom/node.c @@ -178,15 +178,29 @@ const zend_function_entry php_dom_node_class_functions[] = { /* {{{ */ static void dom_reconcile_ns(xmlDocPtr doc, xmlNodePtr nodep) /* {{{ */ { - xmlNsPtr nsptr; + xmlNsPtr nsptr, nsdftptr, curns, prevns = NULL; if (nodep->type == XML_ELEMENT_NODE) { /* Following if block primarily used for inserting nodes created via createElementNS */ - if (nodep->nsDef != NULL && nodep->nsDef->href != NULL) { - if((nsptr = xmlSearchNsByHref(doc, nodep->parent, nodep->nsDef->href)) && - (nodep->nsDef->prefix == NULL || xmlStrEqual(nsptr->prefix, nodep->nsDef->prefix))) { - dom_set_old_ns(doc, nodep->nsDef); - nodep->nsDef = NULL; + if (nodep->nsDef != NULL) { + curns = nodep->nsDef; + while (curns) { + nsdftptr = curns->next; + if (curns->href != NULL) { + if((nsptr = xmlSearchNsByHref(doc, nodep->parent, curns->href)) && + (curns->prefix == NULL || xmlStrEqual(nsptr->prefix, curns->prefix))) { + curns->next = NULL; + if (prevns == NULL) { + nodep->nsDef = nsdftptr; + } else { + prevns->next = nsdftptr; + } + dom_set_old_ns(doc, curns); + curns = prevns; + } + } + prevns = curns; + curns = nsdftptr; } } xmlReconciliateNs(doc, nodep); diff --git a/ext/dom/tests/bug46185.phpt b/ext/dom/tests/bug46185.phpt new file mode 100644 index 0000000000..02117cdd67 --- /dev/null +++ b/ext/dom/tests/bug46185.phpt @@ -0,0 +1,23 @@ +--TEST-- +Bug #46185 (importNode changes the namespace of an XML element). +--SKIPIF-- + +--FILE-- +loadXML(' +'); +$a= $aDOM->firstChild; + +$ok = new DOMDocument(); +$ok->loadXML(' +'); + +$imported= $aDOM->importNode($ok->firstChild, true); +$a->appendChild($imported); + +echo $aDOM->saveXML(); +?> +--EXPECT-- + + \ No newline at end of file