From 69ed9840efde5e1d9dfc819b8c1046dd6ea7a160 Mon Sep 17 00:00:00 2001 From: Rob Richards Date: Thu, 3 Dec 2009 20:19:38 +0000 Subject: [PATCH] fix bug #47848 (importNode doesn't preserve attribute namespaces) add tests --- NEWS | 1 + ext/dom/document.c | 12 ++++++++++++ ext/dom/tests/bug47848.phpt | 25 +++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 ext/dom/tests/bug47848.phpt diff --git a/NEWS b/NEWS index b57138c264e..3990c81cea8 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ PHP NEWS - Fixed bug #49660 (libxml 2.7.3+ limits text nodes to 10MB). (Felipe) - Fixed bug #49472 (Constants defined in Interfaces can be overridden). (Felipe) +- Fixed bug #47848 (importNode doesn't preserve attribute namespaces). (Rob) - Fixed bug #45120 (PDOStatement->execute() returns true then false for same statement). (Pierrick) diff --git a/ext/dom/document.c b/ext/dom/document.c index 7cd3101dbf9..28de8d80299 100644 --- a/ext/dom/document.c +++ b/ext/dom/document.c @@ -1252,6 +1252,18 @@ PHP_FUNCTION(dom_document_import_node) if (!retnodep) { RETURN_FALSE; } + + if ((retnodep->type == XML_ATTRIBUTE_NODE) && (nodep->ns != NULL)) { + xmlNsPtr nsptr = NULL; + xmlNodePtr root = xmlDocGetRootElement(docp); + + nsptr = xmlSearchNsByHref (nodep->doc, root, nodep->ns->href); + if (nsptr == NULL) { + int errorcode; + nsptr = dom_get_ns(root, nodep->ns->href, &errorcode, nodep->ns->prefix); + } + xmlSetNs(retnodep, nsptr); + } } diff --git a/ext/dom/tests/bug47848.phpt b/ext/dom/tests/bug47848.phpt new file mode 100644 index 00000000000..b4453c72091 --- /dev/null +++ b/ext/dom/tests/bug47848.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug #47848 (importNode doesn't preserve attribute namespaces) +--SKIPIF-- + +--FILE-- +appendChild($aDOM->createElementNS('http://friend2friend.net/','f2f:a')); + +$fromdom = new DOMDocument(); +$fromdom->loadXML(''); + +$attr= $fromdom->firstChild->attributes->item(0); + +$att = $aDOM->importNode($attr); + +$aDOM->documentElement->appendChild($aDOM->importNode($attr, true)); + +echo $aDOM->saveXML(); + +?> +--EXPECT-- + + \ No newline at end of file