[php-src] master: Merge branch 'PHP-8.6'
| From: | Ilia Alshanetsky | Date: | Fri, 27 Nov 2026 10:24:27 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-144255@lists.php.net to get a copy of this message | ||
Author: Ilia Alshanetsky (iliaal)
Date: 2026-11-27T05:20:48-05:00
Commit: https://github.com/php/php-src/commit/ef884befbf33a4d8921b94ed4a9acb7255f4fda1
Raw diff: https://github.com/php/php-src/commit/ef884befbf33a4d8921b94ed4a9acb7255f4fda1.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
ext/dom: Reject DTD declaration nodes in adoptNode()
Changed paths:
A ext/dom/tests/modern/spec/XMLDocument_adoptNode_dtd_declarations.phpt
M ext/dom/document.c
Diff:
diff --git a/ext/dom/document.c b/ext/dom/document.c
index 091fa12b301a..f89f878d7057 100644
--- a/ext/dom/document.c
+++ b/ext/dom/document.c
@@ -1208,6 +1208,9 @@ static void dom_document_adopt_node(INTERNAL_FUNCTION_PARAMETERS, bool modern)
|| nodep->type == XML_DOCUMENT_TYPE_NODE
|| nodep->type == XML_DTD_NODE
|| nodep->type == XML_ENTITY_NODE
+ || nodep->type == XML_ELEMENT_DECL
+ || nodep->type == XML_ATTRIBUTE_DECL
+ || nodep->type == XML_ENTITY_DECL
|| nodep->type == XML_NOTATION_NODE)) {
php_dom_throw_error(NOT_SUPPORTED_ERR, dom_get_strict_error(dom_object_nodep->document));
RETURN_FALSE;
diff --git a/ext/dom/tests/modern/spec/XMLDocument_adoptNode_dtd_declarations.phpt
b/ext/dom/tests/modern/spec/XMLDocument_adoptNode_dtd_declarations.phpt
new file mode 100644
index 000000000000..3ffa3dff7005
--- /dev/null
+++ b/ext/dom/tests/modern/spec/XMLDocument_adoptNode_dtd_declarations.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Dom\Document::adoptNode() rejects DTD declarations
+--EXTENSIONS--
+dom
+--FILE--
+<?php
+$xml = '<!DOCTYPE root [<!ELEMENT root EMPTY><!ENTITY ent
"value">]><root/>';
+$source = Dom\XMLDocument::createFromString($xml);
+$target = Dom\XMLDocument::createFromString('<target/>');
+
+$nodes = [
+ $source->doctype->childNodes->item(0),
+ $source->doctype->entities->item(0),
+];
+
+foreach ($nodes as $node) {
+ try {
+ $target->adoptNode($node);
+ echo "adopted\n";
+ } catch (DOMException $e) {
+ echo $e::class, ": ", $e->getCode(), "\n";
+ }
+}
+?>
+--EXPECT--
+DOMException: 9
+DOMException: 9