Skip to content

Commit 1cf2d21

Browse files
committed
Fix DOMCharacterData::replaceWith() with itself
Previously, when replacing the node with itself (or contained within itself), the node disappeared. Closes GH-11770.
1 parent 168bc81 commit 1cf2d21

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ PHP NEWS
1010
. Fix DOMEntity field getter bugs. (nielsdos)
1111
. Fix incorrect attribute existence check in DOMElement::setAttributeNodeNS.
1212
(nielsdos)
13+
. Fix DOMCharacterData::replaceWith() with itself. (nielsdos)
1314

1415
- FFI:
1516
. Fix leaking definitions when using FFI::cdef()->new(...). (ilutov)

ext/dom/characterdata.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,7 @@ PHP_METHOD(DOMCharacterData, replaceWith)
410410
id = ZEND_THIS;
411411
DOM_GET_OBJ(context, id, xmlNodePtr, intern);
412412

413-
dom_parent_node_after(intern, args, argc);
414-
dom_child_node_remove(intern);
413+
dom_child_replace_with(intern, args, argc);
415414
}
416415

417416
#endif
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
DOMCharacterData::replaceWith() with itself
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$dom = new DOMDocument;
8+
$dom->loadXML('<?xml version="1.0"?><container><![CDATA[Hello]]></container>');
9+
$cdata = $dom->documentElement->firstChild;
10+
$cdata->replaceWith($cdata);
11+
echo $dom->saveXML();
12+
?>
13+
--EXPECT--
14+
<?xml version="1.0"?>
15+
<container><![CDATA[Hello]]></container>

0 commit comments

Comments
 (0)