Skip to content

Commit e127f87

Browse files
committed
Restore old namespace reconciliation behaviour
The xmlDOMWrapReconcileNamespaces method we used to fix the namespace corruption issues in 8.1.21/8.2.8 caused regressions. Primarily, there is a similar corruption that the xmlReconciliateNs method used to have in which a namespace is suddenly shifted (SAML-Toolkits/php-saml#562) and the side-effect of removing redundant namespaces causes problems when a specific serialization is required. Closes GH-12308.
1 parent 07811b6 commit e127f87

File tree

6 files changed

+45
-6
lines changed

6 files changed

+45
-6
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ PHP NEWS
1313
. Fixed bug GH-11997 (ctype_alnum 5 times slower in PHP 8.1 or greater).
1414
(nielsdos)
1515

16+
- DOM:
17+
. Restore old namespace reconciliation behaviour. (nielsdos)
18+
1619
- Filter:
1720
. Fix explicit FILTER_REQUIRE_SCALAR with FILTER_CALLBACK (ilutov)
1821

ext/dom/php_dom.c

+5
Original file line numberDiff line numberDiff line change
@@ -1489,11 +1489,16 @@ static void dom_reconcile_ns_internal(xmlDocPtr doc, xmlNodePtr nodep, xmlNodePt
14891489

14901490
static void dom_libxml_reconcile_ensure_namespaces_are_declared(xmlNodePtr nodep)
14911491
{
1492+
/* Ideally we'd use the DOM-wrapped version, but we cannot: https://github.com/php/php-src/pull/12308. */
1493+
#if 0
14921494
/* Put on stack to avoid allocation.
14931495
* Although libxml2 currently does not use this for the reconciliation, it still
14941496
* makes sense to do this just in case libxml2's internal change in the future. */
14951497
xmlDOMWrapCtxt dummy_ctxt = {0};
14961498
xmlDOMWrapReconcileNamespaces(&dummy_ctxt, nodep, /* options */ 0);
1499+
#else
1500+
xmlReconciliateNs(nodep->doc, nodep);
1501+
#endif
14971502
}
14981503

14991504
void dom_reconcile_ns(xmlDocPtr doc, xmlNodePtr nodep) /* {{{ */

ext/dom/tests/bug47530.phpt

+6-6
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,18 @@ test_appendChild_with_shadowing();
118118
--EXPECT--
119119
-- Test document fragment with import --
120120
<?xml version="1.0"?>
121-
<html xmlns="https://php.net/something" xmlns:ns="https://php.net/whatever"><element ns:foo="https://php.net/bar"/></html>
121+
<html xmlns="https://php.net/something" xmlns:ns="https://php.net/whatever"><default:element xmlns:default="https://php.net/something" ns:foo="https://php.net/bar"/></html>
122122
-- Test document fragment without import --
123123
<?xml version="1.0"?>
124-
<html xmlns=""><element xmlns:foo="https://php.net/bar"><foo:bar/><bar xmlns=""/></element></html>
124+
<html xmlns=""><element xmlns:foo="https://php.net/bar"><foo:bar/><bar/></element></html>
125125
string(7) "foo:bar"
126126
string(19) "https://php.net/bar"
127127
-- Test document import --
128128
<?xml version="1.0"?>
129-
<feed xmlns="http://www.w3.org/2005/Atom">
130-
<div xmlns="http://www.w3.org/1999/xhtml">
131-
<p>Test-Text</p>
132-
</div>
129+
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:default="http://www.w3.org/1999/xhtml">
130+
<default:div xmlns="http://www.w3.org/1999/xhtml">
131+
<default:p>Test-Text</default:p>
132+
</default:div>
133133
</feed>
134134
-- Test partial document import --
135135
<?xml version="1.0"?>

ext/dom/tests/bug47847.phpt

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Bug #47847 (importNode loses the namespace of an XML element)
33
--EXTENSIONS--
44
dom
5+
--XFAIL--
6+
See https://github.com/php/php-src/pull/12308
57
--FILE--
68
<?php
79
$fromdom = new DOMDocument();

ext/dom/tests/bug55294.phpt

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Bug #55294 (DOMDocument::importNode shifts namespaces when "default" namespace exists)
33
--EXTENSIONS--
44
dom
5+
--XFAIL--
6+
See https://github.com/php/php-src/pull/12308
57
--FILE--
68
<?php
79

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
DOM: specific namespace behaviour for applications with fixed serialization requirements
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$dom1 = new DOMDocument();
9+
$dom1->loadXML(<<<XML
10+
<wsse:Security xmlns:wsse="foo:bar">
11+
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
12+
</ds:Signature>
13+
</wsse:Security>
14+
XML);
15+
$dom2 = new DOMDocument();
16+
$dom2->loadXML('<xml><child/></xml>');
17+
$wsse = $dom2->importNode($dom1->documentElement, true);
18+
$dom2->firstChild->firstChild->appendChild($wsse);
19+
echo $dom2->saveXML();
20+
21+
?>
22+
--EXPECT--
23+
<?xml version="1.0"?>
24+
<xml><child><wsse:Security xmlns:wsse="foo:bar" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
25+
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
26+
</ds:Signature>
27+
</wsse:Security></child></xml>

0 commit comments

Comments
 (0)