[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-cvs
Subject:    [PHP-CVS] cvs: php-src(PHP_5_3) /ext/dom node.c  /ext/dom/tests bug46185.phpt
From:       "Rob Richards" <rrichards () php ! net>
Date:       2008-09-29 16:52:45
Message-ID: cvsrrichards1222707165 () cvsserver
[Download RAW message or body]

rrichards		Mon Sep 29 16:52:45 2008 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/ext/dom/tests	bug46185.phpt 

  Modified files:              
    /php-src/ext/dom	node.c 
  Log:
  MFH: fix bug #46185 (importNode changes the namespace of an XML element)
  add test
  
http://cvs.php.net/viewvc.cgi/php-src/ext/dom/node.c?r1=1.37.2.3.2.8.2.7&r2=1.37.2.3.2.8.2.8&diff_format=u
                
Index: php-src/ext/dom/node.c
diff -u php-src/ext/dom/node.c:1.37.2.3.2.8.2.7 \
                php-src/ext/dom/node.c:1.37.2.3.2.8.2.8
--- php-src/ext/dom/node.c:1.37.2.3.2.8.2.7	Mon Sep 22 15:09:46 2008
+++ php-src/ext/dom/node.c	Mon Sep 29 16:52:45 2008
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: node.c,v 1.37.2.3.2.8.2.7 2008/09/22 15:09:46 rrichards Exp $ */
+/* $Id: node.c,v 1.37.2.3.2.8.2.8 2008/09/29 16:52:45 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -178,15 +178,29 @@
 
 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);

http://cvs.php.net/viewvc.cgi/php-src/ext/dom/tests/bug46185.phpt?view=markup&rev=1.1
Index: php-src/ext/dom/tests/bug46185.phpt
+++ php-src/ext/dom/tests/bug46185.phpt
--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>


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic