From ee7b914b9d419d6768011eacdbd23debaa9b323f Mon Sep 17 00:00:00 2001 From: imattas Date: Wed, 25 Nov 2026 13:19:45 -0500 Subject: [PATCH 1/2] Reject DTD declarations in adoptNode --- ext/dom/document.c | 3 +++ ...MLDocument_adoptNode_dtd_declarations.phpt | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 ext/dom/tests/modern/spec/XMLDocument_adoptNode_dtd_declarations.phpt diff --git a/ext/dom/document.c b/ext/dom/document.c index c7dd8a0c7a00..3d327f3f4f4f 100644 --- a/ext/dom/document.c +++ b/ext/dom/document.c @@ -1213,6 +1213,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..39b8c9d8410f --- /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-- +]>'; +$source = Dom\XMLDocument::createFromString($xml); +$target = Dom\XMLDocument::createFromString(''); + +$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->getCode(), "\n"; + } +} +?> +--EXPECT-- +9 +9 \ No newline at end of file From 0fcc5859d62f8ae099f070d0e0a1d6c307f7a3a9 Mon Sep 17 00:00:00 2001 From: imattas Date: Wed, 25 Nov 2026 15:31:34 -0500 Subject: [PATCH 2/2] Add trailing newline to adoptNode PHPT --- .../modern/spec/XMLDocument_adoptNode_dtd_declarations.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/dom/tests/modern/spec/XMLDocument_adoptNode_dtd_declarations.phpt b/ext/dom/tests/modern/spec/XMLDocument_adoptNode_dtd_declarations.phpt index 39b8c9d8410f..be9cd807ce3f 100644 --- a/ext/dom/tests/modern/spec/XMLDocument_adoptNode_dtd_declarations.phpt +++ b/ext/dom/tests/modern/spec/XMLDocument_adoptNode_dtd_declarations.phpt @@ -24,4 +24,4 @@ foreach ($nodes as $node) { ?> --EXPECT-- 9 -9 \ No newline at end of file +9