rrichards Thu, 03 Dec 2009 20:19:38 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=291669
Log: fix bug #47848 (importNode doesn't preserve attribute namespaces) add tests Bug: http://bugs.php.net/47848 (Open) importNode doesn't preserve attribute namespaces Changed paths: U php/php-src/branches/PHP_5_2/NEWS U php/php-src/branches/PHP_5_2/ext/dom/document.c A php/php-src/branches/PHP_5_2/ext/dom/tests/bug47848.phpt U php/php-src/branches/PHP_5_3/ext/dom/document.c A php/php-src/branches/PHP_5_3/ext/dom/tests/bug47848.phpt U php/php-src/trunk/ext/dom/document.c A php/php-src/trunk/ext/dom/tests/bug47848.phpt Modified: php/php-src/branches/PHP_5_2/NEWS =================================================================== --- php/php-src/branches/PHP_5_2/NEWS 2009-12-03 19:53:13 UTC (rev 291668) +++ php/php-src/branches/PHP_5_2/NEWS 2009-12-03 20:19:38 UTC (rev 291669) @@ -14,6 +14,7 @@ - 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) Modified: php/php-src/branches/PHP_5_2/ext/dom/document.c =================================================================== --- php/php-src/branches/PHP_5_2/ext/dom/document.c 2009-12-03 19:53:13 UTC (rev 291668) +++ php/php-src/branches/PHP_5_2/ext/dom/document.c 2009-12-03 20:19:38 UTC (rev 291669) @@ -1252,6 +1252,18 @@ 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); + } } Added: php/php-src/branches/PHP_5_2/ext/dom/tests/bug47848.phpt =================================================================== --- php/php-src/branches/PHP_5_2/ext/dom/tests/bug47848.phpt (rev 0) +++ php/php-src/branches/PHP_5_2/ext/dom/tests/bug47848.phpt 2009-12-03 20:19:38 UTC (rev 291669) @@ -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 Modified: php/php-src/branches/PHP_5_3/ext/dom/document.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/dom/document.c 2009-12-03 19:53:13 UTC (rev 291668) +++ php/php-src/branches/PHP_5_3/ext/dom/document.c 2009-12-03 20:19:38 UTC (rev 291669) @@ -1203,7 +1203,18 @@ 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); Added: php/php-src/branches/PHP_5_3/ext/dom/tests/bug47848.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/dom/tests/bug47848.phpt (rev 0) +++ php/php-src/branches/PHP_5_3/ext/dom/tests/bug47848.phpt 2009-12-03 20:19:38 UTC (rev 291669) @@ -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 Modified: php/php-src/trunk/ext/dom/document.c =================================================================== --- php/php-src/trunk/ext/dom/document.c 2009-12-03 19:53:13 UTC (rev 291668) +++ php/php-src/trunk/ext/dom/document.c 2009-12-03 20:19:38 UTC (rev 291669) @@ -1205,7 +1205,18 @@ 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); Added: php/php-src/trunk/ext/dom/tests/bug47848.phpt =================================================================== --- php/php-src/trunk/ext/dom/tests/bug47848.phpt (rev 0) +++ php/php-src/trunk/ext/dom/tests/bug47848.phpt 2009-12-03 20:19:38 UTC (rev 291669) @@ -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
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php