php-src/ext/dom/tests/gh12616_2.phpt
Niels Dossche 3167d07603 Fix GH-12616: DOM: Removing XMLNS namespace node results in invalid default: prefix
The namespace data is freed and set to NULL, but there remain references
to the namespace declaration nodes. This (rightfully) confuses libxml2
because its invariants are broken. We also have to remove all remaining
references from the subtree. This fixes the data corruption bug.

Closes GH-12681.
2023-11-17 19:47:08 +01:00

40 lines
887 B
PHP

--TEST--
GH-12616 (DOM: Removing XMLNS namespace node results in invalid default: prefix)
--EXTENSIONS--
dom
--FILE--
<?php
$doc = new DOMDocument();
$doc->loadXML(
<<<XML
<container xmlns:test="urn:test" xmlns:symfony="http://symfony.com/schema/dic/services">
<symfony:services>
<test:service id="hello" />
</symfony:services>
</container>
XML
);
$doc->documentElement->removeAttributeNS('http://symfony.com/schema/dic/services', 'symfony');
$xpath = new DOMXPath($doc);
$xpath->registerNamespace('test', 'urn:test');
echo $doc->saveXML();
$result = $xpath->query('//container/services/test:service[@id="hello"]');
var_dump($result);
?>
--EXPECT--
<?xml version="1.0"?>
<container xmlns:test="urn:test">
<services>
<test:service id="hello"/>
</services>
</container>
object(DOMNodeList)#4 (1) {
["length"]=>
int(1)
}