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: 2021-11-21 11:55 UTC
From: jules dot bernable at gmail dot com Assigned:
Status: Open Package: DOM XML related
PHP Version: 8.0.0 OS: debian unstable
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jules dot bernable at gmail dot com
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-21 11:55 UTC] patrickallaert@php.net
-PHP Version: 8.1.0RC6 +PHP Version: 8.0.0
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Jan 19 20:03:14 2022 UTC