summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Richards <rrichards@php.net>2009-12-03 20:19:38 +0000
committerRob Richards <rrichards@php.net>2009-12-03 20:19:38 +0000
commit3fa1ea973128f28e30914f1c564be0ff56a4dcef (patch)
treeaf374d102914f9fbaf90dad1d4735ee19d5e7b31
parente2efe4bc7b96febe5b7938128ea6b1ce8f605cf3 (diff)
downloadphp-git-3fa1ea973128f28e30914f1c564be0ff56a4dcef.tar.gz
fix bug #47848 (importNode doesn't preserve attribute namespaces)
add tests
-rw-r--r--ext/dom/document.c13
-rw-r--r--ext/dom/tests/bug47848.phpt25
2 files changed, 37 insertions, 1 deletions
diff --git a/ext/dom/document.c b/ext/dom/document.c
index e2d87b05c9..f82d7667c6 100644
--- a/ext/dom/document.c
+++ b/ext/dom/document.c
@@ -1203,7 +1203,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);
+ }
}
DOM_RET_OBJ(rv, (xmlNodePtr) retnodep, &ret, intern);
diff --git a/ext/dom/tests/bug47848.phpt b/ext/dom/tests/bug47848.phpt
new file mode 100644
index 0000000000..b4453c7209
--- /dev/null
+++ b/ext/dom/tests/bug47848.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Bug #47848 (importNode doesn't preserve attribute namespaces)
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+
+$aDOM = new DOMDocument();
+$aDOM->appendChild($aDOM->createElementNS('http://friend2friend.net/','f2f:a'));
+
+$fromdom = new DOMDocument();
+$fromdom->loadXML('<data xmlns:ai="http://altruists.org" ai:attr="namespaced" />');
+
+$attr= $fromdom->firstChild->attributes->item(0);
+
+$att = $aDOM->importNode($attr);
+
+$aDOM->documentElement->appendChild($aDOM->importNode($attr, true));
+
+echo $aDOM->saveXML();
+
+?>
+--EXPECT--
+<?xml version="1.0"?>
+<f2f:a xmlns:f2f="http://friend2friend.net/" xmlns:ai="http://altruists.org" ai:attr="namespaced"/> \ No newline at end of file