Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions ext/dom/parentnode/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,11 @@ static bool dom_is_pre_insert_valid_without_step_1(php_libxml_ref_obj *document,
ZEND_ASSERT(parentNode != NULL);

/* 1. If parent is not a Document, DocumentFragment, or Element node, then throw a "HierarchyRequestError" DOMException.
* => Impossible */
ZEND_ASSERT(!php_dom_pre_insert_is_parent_invalid(parentNode));
* => This is possible because we can grab children of attributes etc... (see e.g. GH-16594) */
if (php_dom_pre_insert_is_parent_invalid(parentNode)) {
php_dom_throw_error(HIERARCHY_REQUEST_ERR, dom_get_strict_error(document));
return false;
}

if (node->doc != documentNode) {
php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(document));
Expand Down
25 changes: 25 additions & 0 deletions ext/dom/tests/gh16594.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
GH-16594 (Assertion failure in DOM -> before)
--EXTENSIONS--
dom
--FILE--
<?php

$v1 = new DOMText("wr");
$v2 = new DOMDocument();
$v6 = new DOMComment("aw");
$v7 = new DOMAttr("r", "iL");

$v9 = $v2->createElement("test");
$v9->setAttributeNodeNS($v7);
$v7->appendChild($v1);

try {
$v1->before($v6);
} catch (DOMException $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECT--
Hierarchy Request Error