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..be9cd807ce3f --- /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