1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/ext/dom/tests/modern/xml/gh20444.phpt
Niels Dossche 40c291cf93 Fix GH-20444: Dom\XMLDocument::C14N() seems broken compared to DOMDocument::C14N()
C14N code expects namespace to be in-tree, but we store namespaces in a
different way out-of-tree to avoid reconciliations that break the tree
structure in a way unexpected by the DOM spec. In the DOM spec,
namespace nodes don't exist; they're regular attributes.
To solve this, we temporarily make fake namespace nodes that we later
remove.

Closes GH-20457.
2025-12-26 22:27:25 +01:00

44 lines
982 B
PHP

--TEST--
GH-20444 (Dom\XMLDocument::C14N() seems broken compared to DOMDocument::C14N())
--EXTENSIONS--
dom
--FILE--
<?php
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<test:root xmlns:test="http://example.com/dummy/ns">
<test:a xmlns:test="http://example.com/dummy/ns"/>
<test:b test:kind="123">abc</test:b>
</test:root>
EOF;
$d = \Dom\XMLDocument::createFromString($xml);
var_dump($d->C14N(true));
$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<ns1:root xmlns:ns1="http://example.com/dummy/ns">
<ns1:a/>
<ns1:b>
<ns1:c>123</ns1:c>
</ns1:b>
</ns1:root>
EOF;
$d = \Dom\XMLDocument::createFromString($xml);
var_dump($d->C14N());
?>
--EXPECT--
string(128) "<test:root xmlns:test="http://example.com/dummy/ns">
<test:a></test:a>
<test:b test:kind="123">abc</test:b>
</test:root>"
string(134) "<ns1:root xmlns:ns1="http://example.com/dummy/ns">
<ns1:a></ns1:a>
<ns1:b>
<ns1:c>123</ns1:c>
</ns1:b>
</ns1:root>"