Bug #81468 [NEW]: Inconsistent default namespace inheritance
| From: | dennis dot verspuij+php at gmail dot com | Date: | Thu, 23 Sep 2021 09:03:57 +0000 |
| Subject: | Bug #81468 [NEW]: Inconsistent default namespace inheritance | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-236767@lists.php.net to get a copy of this message | ||
From: dennis dot verspuij+php at gmail dot com
Operating system:
PHP version: 8.0.10
Package: DOM XML related
Bug Type: Bug
Bug description:Inconsistent default namespace inheritance
Description:
------------
A child node created with DOMDocument::createElement() added to an
element with a non-empty default namespace internally does not seem to
inherit the default namespace of the parent, while when saving the XML
it looks like it does.
And imho it should inherit the namespace, because a node created with
createElement() does not yet have a namespace until it is added
somewhere in the document (hence parameter name localName). In contrary
a node created with createElementNS() keeps its explicit namespace once
added anywhere.
Not sure if this a libxml bug, or a bug in PHP xml extension.
Test script:
---------------
<?php
$dom = new \DOMDocument();
$dom
->appendChild($dom->createElementNS('some:namespace', 'foo'))
->appendChild($dom->createElement('bar'));
echo ($xml = $dom->saveXML());
$xpath = new \DOMXPath($dom);
$xpath->registerNamespace('n', 'some:namespace');
echo count($xpath->query('/n:foo/bar')) . " should be 0\n";
echo count($xpath->query('/n:foo/n:bar')) . " should be 1\n\n";
//
$dom = new \DOMDocument();
$dom->loadXml($xml);
echo ($xml = $dom->saveXML());
$xpath = new \DOMXPath($dom);
$xpath->registerNamespace('n', 'some:namespace');
echo count($xpath->query('/n:foo/bar')) . " should be 0\n";
echo count($xpath->query('/n:foo/n:bar')) . " should be 1\n\n";
Expected result:
----------------
See test script and output.
Actual result:
--------------
See test script and output.
--
Edit bug report at https://bugs.php.net/bug.php?id=81468&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81468&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81468&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81468&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81468&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81468&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81468&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81468&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81468&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81468&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81468&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81468&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81468&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81468&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81468&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81468&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81468&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81468&r=mysqlcfg