php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81642 DOMChildNode::replaceWith() bug when replacing a node with itself.
Submitted: 2021-11-19 16:51 UTC Modified: 2022-04-25 12:59 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jules dot bernable at gmail dot com Assigned: beberlei (profile)
Status: Closed Package: DOM XML related
PHP Version: 8.0.0 OS: debian unstable
Private report: No CVE-ID: None
 [2021-11-19 16:51 UTC] jules dot bernable at gmail dot com
Description:
------------
When calling `DOMChildNode::replaceWith()` on a given node,
If the node is also part of the argument list, PHP either throws a DOMException or just hangs indefinitely.

The bug is present at least in versions 8.0.12 and 8.1.0RC6

Test script:
---------------
// example 1
$doc = new DOMDocument();
$doc->appendChild($target = $doc->createElement('test'));
$target->replaceWith($target); // PHP Fatal error:  Uncaught DOMException: Not Found Error

// example 2
$doc = new DOMDocument();
$doc->appendChild($target = $doc->createElement('test'));
$target->replaceWith($target, 'foo'); // program hangs indefinitely

Expected result:
----------------
Both examples should be handled correctly, like browsers do.


Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-21 11:55 UTC] patrickallaert@php.net
-PHP Version: 8.1.0RC6 +PHP Version: 8.0.0
 [2022-04-25 12:59 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: beberlei
 [2022-04-25 12:59 UTC] cmb@php.net
I can confirm the reported issues.

Benjamin, could you have a look at this?
 [2022-06-10 09:22 UTC] afshin dot meh at gmail dot com
I'm happy to look into this as well if it's not being worked on yet?
 [2022-09-13 18:14 UTC] stri73971 at gmail dot com
The following pull request has been associated:

Patch Name: Fixed and simplified array_replace description
On GitHub:  https://github.com/php/doc-de/pull/76
Patch:      https://github.com/php/doc-de/pull/76.patch
 [2022-11-30 05:15 UTC] hazerissa1 at gmail dot com
the issue is that when we boot a node with --replace_address_first_boot, the node maybe set with itself being a seed - in this case the node currently boots and may set its token on its own instead of taking the old node tokens.

<https://www.mylabcorp.me/>github.com
 [2022-12-03 05:39 UTC] maypayne146 at gmail dot com
The Element.replaceWith () method replaces this Element in the children list of its parent with a set of Node or string objects. String objects are inserted as equivalent Text nodes. A set of Node or string objects to replace. None ( undefined ). Thrown when the node cannot be inserted at the specified point in the hierarchy.


<https://www.fragomen-connect.com/>github.com
 [2022-12-13 05:10 UTC] EvanMartin at jourrapide dot com
The childNodes property is a property of Node in Javascript and is used to return a Nodelist of child nodes.

<https://www.gmglobalconnect.me/>github.com
 [2022-12-15 08:16 UTC] MasonCooke at teleworm dot us
English PHP documentation. Contribute to php/doc-en development by creating an account on GitHub.

<https://www.myehtrip.me/>github.com
 [2022-12-16 05:24 UTC] LiamBaker at teleworm dot us
DOMChildNode.cpp Go to the documentation of this file. 00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements.

<https://www.myccpay.fyi/>github.com
 [2022-12-20 09:16 UTC] fosliffebernie at gmail dot com
DOMChildNode.cpp Go to the documentation of this file. 00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements.

<https://www.mywafflehouse.net/>github.com
 [2022-12-24 04:48 UTC] OscarHutchinson at dayrep dot com
English PHP documentation. Contribute to php/doc-en development by creating an account on GitHub.

<https://www.hisdconnect.net/>github.com
 [2023-01-03 08:55 UTC] fosliffebernie at gmail dot com
<https://www.mywafflehouse.us/>github.com
 [2023-01-09 09:37 UTC] fosliffebernie at gmail dot com
If you are trying to replace more than one node at once, you have to be careful about iterating over the DOMNodeList. If the old node has a different name from the new node, it will be removed from the list once it has been replaced. Use a regressive loop: $newelement = $xml>createTextNode('Some new node!');

<https://www.novitasphere.us/>github.com
 [2023-01-10 08:07 UTC] LouiseTalbot at rhyta dot com
The childNodes property returns a NodeList containing the child nodes of the selected node If the selected node has no children, this property returns a NodeList containing no nodes.

<https://www.thirtyonetoday.me/>github.com
 [2023-01-13 06:09 UTC] LewisDickinson at rhyta dot com
The childNodes property returns a NodeList containing the child nodes of the selected node If the selected node has no children, this property returns a NodeList containing no nodes.

<https://www.novita-sphere.com/>github.com
 [2023-06-04 14:35 UTC] git@php.net
Automatic comment on behalf of nielsdos
Revision: https://github.com/php/php-src/commit/23f70025270c040e0d378b210120d9824af10ea6
Log: Fix bug #81642: DOMChildNode::replaceWith() bug when replacing a node with itself
 [2023-06-04 14:35 UTC] git@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 10:01:29 2024 UTC