mirror of
https://github.com/php/php-src.git
synced 2025-08-18 15:08:55 +02:00
fix bug #46185 (importNode changes the namespace of an XML element)
add test
This commit is contained in:
parent
08be04b2d9
commit
00b84bb1fd
2 changed files with 43 additions and 6 deletions
|
@ -178,15 +178,29 @@ const zend_function_entry php_dom_node_class_functions[] = { /* {{{ */
|
||||||
|
|
||||||
static void dom_reconcile_ns(xmlDocPtr doc, xmlNodePtr nodep) /* {{{ */
|
static void dom_reconcile_ns(xmlDocPtr doc, xmlNodePtr nodep) /* {{{ */
|
||||||
{
|
{
|
||||||
xmlNsPtr nsptr;
|
xmlNsPtr nsptr, nsdftptr, curns, prevns = NULL;
|
||||||
|
|
||||||
if (nodep->type == XML_ELEMENT_NODE) {
|
if (nodep->type == XML_ELEMENT_NODE) {
|
||||||
/* Following if block primarily used for inserting nodes created via createElementNS */
|
/* Following if block primarily used for inserting nodes created via createElementNS */
|
||||||
if (nodep->nsDef != NULL && nodep->nsDef->href != NULL) {
|
if (nodep->nsDef != NULL) {
|
||||||
if((nsptr = xmlSearchNsByHref(doc, nodep->parent, nodep->nsDef->href)) &&
|
curns = nodep->nsDef;
|
||||||
(nodep->nsDef->prefix == NULL || xmlStrEqual(nsptr->prefix, nodep->nsDef->prefix))) {
|
while (curns) {
|
||||||
dom_set_old_ns(doc, nodep->nsDef);
|
nsdftptr = curns->next;
|
||||||
nodep->nsDef = NULL;
|
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);
|
xmlReconciliateNs(doc, nodep);
|
||||||
|
|
23
ext/dom/tests/bug46185.phpt
Normal file
23
ext/dom/tests/bug46185.phpt
Normal file
|
@ -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>
|
Loading…
Add table
Add a link
Reference in a new issue