Skip to content

Commit c66221b

Browse files
authored
Fix arginfo violation in removeChild() (#14717)
It was possible to return false without throwing an exception. This is even wrong in "old DOM" because we expect either a NOT_FOUND_ERR or NO_MODIFICATION_ALLOWED_ERR according to the documentation. A side effect of this patch is that it prioritises NOT_FOUND_ERR over NO_MODIFICATION_ALLOWED_ERR but I think that's fine.
1 parent de8b13f commit c66221b

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

ext/dom/node.c

+5-9
Original file line numberDiff line numberDiff line change
@@ -1229,22 +1229,18 @@ static void dom_node_remove_child(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry
12291229

12301230
DOM_GET_OBJ(nodep, ZEND_THIS, xmlNodePtr, intern);
12311231

1232-
if (!dom_node_children_valid(nodep)) {
1233-
RETURN_FALSE;
1234-
}
1235-
12361232
DOM_GET_OBJ(child, node, xmlNodePtr, childobj);
12371233

12381234
bool stricterror = dom_get_strict_error(intern->document);
12391235

1240-
if (dom_node_is_read_only(nodep) == SUCCESS ||
1241-
(child->parent != NULL && dom_node_is_read_only(child->parent) == SUCCESS)) {
1242-
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror);
1236+
if (!nodep->children || child->parent != nodep) {
1237+
php_dom_throw_error(NOT_FOUND_ERR, stricterror);
12431238
RETURN_FALSE;
12441239
}
12451240

1246-
if (!nodep->children || child->parent != nodep) {
1247-
php_dom_throw_error(NOT_FOUND_ERR, stricterror);
1241+
if (dom_node_is_read_only(nodep) == SUCCESS ||
1242+
(child->parent != NULL && dom_node_is_read_only(child->parent) == SUCCESS)) {
1243+
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror);
12481244
RETURN_FALSE;
12491245
}
12501246

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Removing a child from a comment should result in NOT_FOUND_ERR
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$dom = Dom\XMLDocument::createFromString('<root><!-- comment --><child/></root>');
9+
$comment = $dom->documentElement->firstChild;
10+
$child = $comment->nextSibling;
11+
12+
try {
13+
$comment->removeChild($child);
14+
} catch (DOMException $e) {
15+
echo $e->getMessage(), "\n";
16+
}
17+
18+
?>
19+
--EXPECT--
20+
Not Found Error

0 commit comments

Comments
 (0)