diff options
author | Rob Richards <rrichards@php.net> | 2008-09-29 16:52:45 +0000 |
---|---|---|
committer | Rob Richards <rrichards@php.net> | 2008-09-29 16:52:45 +0000 |
commit | 641347202b9bc0289174357bf0824e1eaa7c9397 (patch) | |
tree | c4c5b8022510b10402afd1d0dd8425b71b06bbd0 | |
parent | 84bfd4040ef49b96495f3820eb633b7ae0386d0b (diff) | |
download | php-git-641347202b9bc0289174357bf0824e1eaa7c9397.tar.gz |
MFH: fix bug #46185 (importNode changes the namespace of an XML element)
add test
-rw-r--r-- | ext/dom/node.c | 26 | ||||
-rw-r--r-- | ext/dom/tests/bug46185.phpt | 23 |
2 files changed, 43 insertions, 6 deletions
diff --git a/ext/dom/node.c b/ext/dom/node.c index 03e64c1897..6363e30f03 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-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +$aDOM = new DOMDocument(); +$aDOM->loadXML('<?xml version="1.0"?> +<ns1:a xmlns:ns1="urn::ns"/>'); +$a= $aDOM->firstChild; + +$ok = new DOMDocument(); +$ok->loadXML('<?xml version="1.0"?> +<ns1:ok xmlns:ns1="urn::ns" xmlns="urn::REAL"><watch-me xmlns:default="urn::BOGUS"/></ns1:ok>'); + +$imported= $aDOM->importNode($ok->firstChild, true); +$a->appendChild($imported); + +echo $aDOM->saveXML(); +?> +--EXPECT-- +<?xml version="1.0"?> +<ns1:a xmlns:ns1="urn::ns"><ns1:ok xmlns="urn::REAL"><watch-me xmlns:default="urn::BOGUS"/></ns1:ok></ns1:a>
\ No newline at end of file |