Bug #55294 [Nab->Csd]: DOMDocument::importNode shifts namespaces when "default" namespace exists

From: Date: Thu, 15 Jun 2023 19:58:09 +0000
Subject: Bug #55294 [Nab->Csd]: DOMDocument::importNode shifts namespaces when "default" namespace exists
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-244700@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55294&edit=1 ID: 55294 Updated by: git@php.net Reported by: hilse at web dot de Summary: DOMDocument::importNode shifts namespaces when "default" namespace exists -Status: Not a bug +Status: Closed Type: Bug Package: DOM XML related Operating System: Linux PHP Version: trunk-SVN-2011-07-27 (snap) Block user comment: N Private report: N New Comment: Automatic comment on behalf of nielsdos Revision: https://github.com/php/php-src/commit/b30be40b86b62fc681c432fd96840d8e57e172a5 Log: Fix bug #55294 and #47530 and #47847: namespace reconciliation issues Previous Comments: ------------------------------------------------------------------------ [2013-12-03 07:45:58] mike@php.net Related To: Bug #47530 ------------------------------------------------------------------------ [2013-12-02 19:40:54] mike@php.net If, then an upstream bug of libxml2. xmlNewReconciliedNS() uses "default" as prefix if not already found in the doc. So either don't use default, or looking at libxml2 sources, default followed by a number in the range 0-1000, or file a bug at http://bugzilla.gnome.org/buglist.cgi?product=libxml2 And on a side note: it happens on append not import. ------------------------------------------------------------------------ [2011-07-27 12:35:16] hilse at web dot de Description: ------------ When importing nodes and their children via DOMDocument::importNode, the method will introduce the "default" namespace prefix. Herein lies a bug that will trigger if the namespace prefix "default" is already assigned (even if not applied to any element) within the children of the imported node. Test script: --------------- <?php $aDOM=DOMDocument::loadXML(<<<EOXML <A xmlns="http://example.hilses.de/A"> <B> <C xmlns="http://example.hilses.de/C" xmlns:default="http://example.hilses.de/Z" /> </B> </A> EOXML ); $bDOM=new DOMDocument(); $node = $bDOM->importNode($aDOM->getElementsByTagNameNS('http://example.hilses.de/A','B')->item(0), true); $bDOM->appendChild($node); echo $bDOM->saveXML()."\n"; ?> Expected result: ---------------- <?xml version="1.0"?> <B xmlns="http://example.hilses.de/A" xmlns:default="http://example.hilses.de/C"> <default:C /> </B> or even better: <?xml version="1.0"?> <B xmlns="http://example.hilses.de/A"> <C xmlns="http://example.hilses.de/C"/> </B> Actual result: -------------- <?xml version="1.0"?> <B xmlns="http://example.hilses.de/A" xmlns:default="http://example.hilses.de/C"> <default:C xmlns="http://example.hilses.de/C" xmlns:default="http://example.hilses.de/Z"/> </B> (see how C is put into the ".../Z" namespace now instead of ".../C", since namespace prefix declarations are valid for the element in which they are defined!) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55294&edit=1

« previous php.bugs (#244700) next »