Bug #47530 [Csd->ReO]: Importing objects into document fragments creates bogus "default" namespace
| From: | nielsdos@php.net | Date: | Wed, 17 Jan 2024 18:45:14 +0000 |
| Subject: | Bug #47530 [Csd->ReO]: Importing objects into document fragments creates bogus "default" namespace | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-246285@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=47530&edit=1
ID: 47530
Updated by: nielsdos@php.net
Reported by: sgunderson at bigfoot dot com
Summary: Importing objects into document fragments creates
bogus "default" namespace
-Status: Closed
+Status: Re-Opened
Type: Bug
Package: DOM XML related
Operating System: Debian
PHP Version: 5.2.9
Assigned To: nielsdos
Block user comment: N
Private report: N
New Comment:
I forgot to re-open this. But long story short: I had to revert this because of BC breaks due to
side-effects of this fix.
This will be fixed (together with other namespace bugs) once and for all once https://github.com/php/php-src/pull/13031 gets
merged.
Previous Comments:
------------------------------------------------------------------------
[2023-06-15 19:59:20] nielsdos@php.net
The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src and re-test.
Thank you for the report, and for helping us make PHP better.
------------------------------------------------------------------------
[2013-12-03 07:45:58] mike@php.net
libxml2 issue.
See also bug #55294
------------------------------------------------------------------------
[2011-01-12 08:34:38] mplomer at gmx dot de
This does not only affect DocumentFragments. I had this problem with a simple importNode() when
having multiple default namespaces. Here is a simplified XML sample:
Reproduce code:
---------------
<?php
$xml = '<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>Test-Text</p>
</div>
</feed>';
$dom = new DOMDocument();
$dom->loadXML($xml);
$dom2 = new DOMDocument();
$importedNode = $dom2->importNode($dom->documentElement, true);
$dom2->appendChild($importedNode);
echo $dom2->saveXML();
?>
Actual result:
--------------
<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:default="http://www.w3.org/1999/xhtml">
<default:div xmlns="http://www.w3.org/1999/xhtml">
<default:p>Test-Text</default:p>
</default:div>
</feed>
------------------------------------------------------------------------
[2009-02-28 14:48:20] sgunderson at bigfoot dot com
Description:
------------
Hi,
When I import a DOM node via a document fragment, suddenly a "default" namespace comes out
of nowhere (and it's really hard to remove, short of making my own cloneNode() simulation
stripping it).
IIRC PHP4 got this right (although it had lots of other issues), and all other languages I've
tested in (Perl, Python, Ruby) do as well. Note that the code below doesn't strictly need
importNode(), but I cannot really do with cloneNode() in the real code (it's vastly
simplified).
Note: On the surface, this appears to be the same bug as #46185, but I tested 5.3 CVS (as of
2009-02-28) and it's still there.
Reproduce code:
---------------
<?php
$doc = new DOMDocument;
$doc->loadXML('<html xmlns="something"
xmlns:ns="whatever"><element ns:foo="bar" /></html>');
$root = $doc->documentElement;
$elem = $root->firstChild;
$frag = $doc->createDocumentFragment();
$frag->appendChild($doc->importNode($elem));
$root->appendChild($frag);
print $doc->saveXML();
?>
Expected result:
----------------
<?xml version="1.0"?>
<html xmlns="something" xmlns:ns="whatever"><element
ns:foo="bar"/></html>
Actual result:
--------------
<?xml version="1.0"?>
<html xmlns="something" xmlns:ns="whatever"><default:element
xmlns:default="something" xmlns:ns="whatever"
ns:foo="bar"/></html>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=47530&edit=1