[php-src] Issue #12455: Namespace prefixes reused incorrectly
| From: | InvisibleSmiley | Date: | Tue, 17 Oct 2023 09:57:24 +0000 |
| Subject: | [php-src] Issue #12455: Namespace prefixes reused incorrectly | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-245592@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/12455
Author: InvisibleSmiley
### Description
The following code:
```php
<?php
$doc = new DOMDocument();
$element = $doc->createElementNS('http://test',
'a:x');
$doc->appendChild($element);
$element1 = $doc->createElementNS('http://test',
'b:y');
$element->appendChild($element1);
$element1->appendChild($doc->createElementNS('http://test', 'b:z'));
echo $doc->saveXml();
$xpath = new DOMXPath($doc);
$xpath->registerNodeNamespaces = true;
$xpath->registerNamespace('b', 'http://test');
$elements = $xpath->query('//b:z');
foreach ($elements as $e) {
var_dump($e->nodeName);
}
$elements = $xpath->query('//*[name()="b:z"]');
echo $elements->length;
```
Resulted in this output:
```
<?xml version="1.0"?>
<a:x xmlns:a="http://test"><b:y xmlns:b="http://test"><a:z/></b:y></a:x>
string(3) "a:z"
0
```
But I expected this output instead:
```
<?xml version="1.0"?>
<a:x xmlns:a="http://test"><b:y xmlns:b="http://test"><b:z/></b:y></a:x>
string(3) "b:z"
1
```
Likely caused by the fix for bug #67440: append_node of a DOMDocumentFragment does not reconcile
namespaces
https://github.com/php/php-src/commit/b1d8e240e688cae810c83b364772bf140ac45f42
Broken since: 8.1.21 / 8.2.8
Last known good: 8.1.20 / 8.2.7
I think the following is relevant in this context, explaining why XML C14N explicitly excluded XML
namespace prefix rewriting: https://datatracker.ietf.org/doc/html/rfc3076#section-4.4
### PHP Version
PHP 8.1.24
### Operating System
MacOS Ventura 13.6