php-src/ext/dom/tests/gh12870.inc
Niels Dossche e658f80501 Fix GH-12870: Creating an xmlns attribute results in a DOMException
There were multiple things here since forever, see the GH thread [1]
for discussion.

There were already many fixes to this function previously, and as a
consequence of one of those fixes this started throwing exceptions for a
correct use-case. It turns out that even when reverting to the previous
behaviour there are still bugs. Just fix all of them while we have the
chance.

[1] https://github.com/php/php-src/issues/12870

Closes GH-12888.
2023-12-07 22:42:32 +01:00

26 lines
982 B
PHP

<?php
function test(?string $uri, string $qualifiedName) {
$uri_readable = is_null($uri) ? 'NULL' : "\"$uri\"";
echo "--- Testing $uri_readable, \"$qualifiedName\" ---\n";
$d = new DOMDocument();
$d->appendChild($d->createElement('root'));
try {
$attr = $d->createAttributeNS($uri, $qualifiedName);
$d->documentElement->setAttributeNodeNS($attr);
echo "Attr prefix: ";
var_dump($attr->prefix);
echo "Attr namespaceURI: ";
var_dump($attr->namespaceURI);
echo "Attr value: ";
var_dump($attr->value);
echo "root namespaceURI: ";
var_dump($d->documentElement->namespaceURI);
echo "Equality check: ";
$parts = explode(':', $qualifiedName);
var_dump($attr === $d->documentElement->getAttributeNodeNS($uri, $parts[count($parts) - 1]));
echo $d->saveXML(), "\n";
} catch (DOMException $e) {
echo "Exception: ", $e->getMessage(), "\n\n";
}
}