Skip to content

Commit 163e16d

Browse files
committed
Align DOMChildNode parent checks with spec
1 parent 505fab1 commit 163e16d

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

UPGRADING

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ PHP 8.3 UPGRADE NOTES
4646
iterating over the WeakMap (reachability via iteration is considered weak).
4747
Previously, such entries would never be automatically removed.
4848

49+
- DOM:
50+
. DOMChildNode::after(), DOMChildNode::before(), DOMChildNode::replaceWith()
51+
on a node that has no parent is now a no-op instead of a hierarchy exception,
52+
which is the behaviour spec demands.
53+
4954
- FFI:
5055
. C functions that have a return type of void now return null instead of
5156
returning the following object object(FFI\CData:void) { }

ext/dom/parentnode.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,6 @@ void dom_parent_node_after(dom_object *context, zval *nodes, uint32_t nodesc)
396396
parentNode = prevsib->parent;
397397
/* Spec step 2 */
398398
if (!parentNode) {
399-
int stricterror = dom_get_strict_error(context->document);
400-
php_dom_throw_error(HIERARCHY_REQUEST_ERR, stricterror);
401399
return;
402400
}
403401

@@ -453,8 +451,6 @@ void dom_parent_node_before(dom_object *context, zval *nodes, uint32_t nodesc)
453451
parentNode = nextsib->parent;
454452
/* Spec step 2 */
455453
if (!parentNode) {
456-
int stricterror = dom_get_strict_error(context->document);
457-
php_dom_throw_error(HIERARCHY_REQUEST_ERR, stricterror);
458454
return;
459455
}
460456

@@ -555,8 +551,6 @@ void dom_child_replace_with(dom_object *context, zval *nodes, uint32_t nodesc)
555551
xmlNodePtr parentNode = child->parent;
556552
/* Spec step 2 */
557553
if (!parentNode) {
558-
int stricterror = dom_get_strict_error(context->document);
559-
php_dom_throw_error(HIERARCHY_REQUEST_ERR, stricterror);
560554
return;
561555
}
562556

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
DOMChildNode methods without a parent
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$doc = new DOMDocument;
8+
$doc->loadXML(<<<XML
9+
<?xml version="1.0"?>
10+
<container>
11+
<child/>
12+
</container>
13+
XML);
14+
15+
$container = $doc->documentElement;
16+
$child = $container->firstElementChild;
17+
18+
$test = $doc->createElement('foo');
19+
foreach (['before', 'after', 'replaceWith'] as $method) {
20+
echo "--- $method ---\n";
21+
$test->$method($child);
22+
echo $doc->saveXML();
23+
echo $doc->saveXML($test), "\n";
24+
}
25+
?>
26+
--EXPECT--
27+
--- before ---
28+
<?xml version="1.0"?>
29+
<container>
30+
<child/>
31+
</container>
32+
<foo/>
33+
--- after ---
34+
<?xml version="1.0"?>
35+
<container>
36+
<child/>
37+
</container>
38+
<foo/>
39+
--- replaceWith ---
40+
<?xml version="1.0"?>
41+
<container>
42+
<child/>
43+
</container>
44+
<foo/>

0 commit comments

Comments
 (0)