From e127f87114cd2d54f960b66a29d5e8f674df8a75 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Wed, 27 Sep 2023 22:32:01 +0200 Subject: [PATCH] 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. --- NEWS | 3 +++ ext/dom/php_dom.c | 5 ++++ ext/dom/tests/bug47530.phpt | 12 ++++----- ext/dom/tests/bug47847.phpt | 2 ++ ext/dom/tests/bug55294.phpt | 2 ++ .../tests/specific_namespace_behaviour.phpt | 27 +++++++++++++++++++ 6 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 ext/dom/tests/specific_namespace_behaviour.phpt diff --git a/NEWS b/NEWS index 6798a29e7e6..15b6a94e0c3 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,9 @@ PHP NEWS . Fixed bug GH-11997 (ctype_alnum 5 times slower in PHP 8.1 or greater). (nielsdos) +- DOM: + . Restore old namespace reconciliation behaviour. (nielsdos) + - Filter: . Fix explicit FILTER_REQUIRE_SCALAR with FILTER_CALLBACK (ilutov) diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index ba532045186..5eea6840b66 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -1489,11 +1489,16 @@ static void dom_reconcile_ns_internal(xmlDocPtr doc, xmlNodePtr nodep, xmlNodePt static void dom_libxml_reconcile_ensure_namespaces_are_declared(xmlNodePtr nodep) { + /* Ideally we'd use the DOM-wrapped version, but we cannot: https://github.com/php/php-src/pull/12308. */ +#if 0 /* Put on stack to avoid allocation. * Although libxml2 currently does not use this for the reconciliation, it still * makes sense to do this just in case libxml2's internal change in the future. */ xmlDOMWrapCtxt dummy_ctxt = {0}; xmlDOMWrapReconcileNamespaces(&dummy_ctxt, nodep, /* options */ 0); +#else + xmlReconciliateNs(nodep->doc, nodep); +#endif } void dom_reconcile_ns(xmlDocPtr doc, xmlNodePtr nodep) /* {{{ */ diff --git a/ext/dom/tests/bug47530.phpt b/ext/dom/tests/bug47530.phpt index 0fb990e0e7b..301a418fbe8 100644 --- a/ext/dom/tests/bug47530.phpt +++ b/ext/dom/tests/bug47530.phpt @@ -118,18 +118,18 @@ test_appendChild_with_shadowing(); --EXPECT-- -- Test document fragment with import -- - + -- Test document fragment without import -- - + string(7) "foo:bar" string(19) "https://php.net/bar" -- Test document import -- - -
-

Test-Text

-
+ + + Test-Text + -- Test partial document import -- diff --git a/ext/dom/tests/bug47847.phpt b/ext/dom/tests/bug47847.phpt index 324bf9508d5..1c9ec95418e 100644 --- a/ext/dom/tests/bug47847.phpt +++ b/ext/dom/tests/bug47847.phpt @@ -2,6 +2,8 @@ Bug #47847 (importNode loses the namespace of an XML element) --EXTENSIONS-- dom +--XFAIL-- +See https://github.com/php/php-src/pull/12308 --FILE-- loadXML(<< + + + +XML); +$dom2 = new DOMDocument(); +$dom2->loadXML(''); +$wsse = $dom2->importNode($dom1->documentElement, true); +$dom2->firstChild->firstChild->appendChild($wsse); +echo $dom2->saveXML(); + +?> +--EXPECT-- + + + + +