[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOMException: Not Found Error introduced in 8.2.6, 8.1.19 #11289

Closed
fluffycondor opened this issue May 22, 2023 · 1 comment
Closed

DOMException: Not Found Error introduced in 8.2.6, 8.1.19 #11289

fluffycondor opened this issue May 22, 2023 · 1 comment

Comments

@fluffycondor
Copy link

Description

Live reproduce: https://3v4l.org/AgHLn

The following code:

<?php

$html = <<<HTML
<!DOCTYPE HTML>
<html>
<body>
    <div></div>
</body>
</html>
HTML;

$dom = new DOMDocument();
$dom->loadHTML($html);

$divs = iterator_to_array($dom->getElementsByTagName('div')->getIterator());
foreach ($divs as $div) {
    $fragment = $dom->createDocumentFragment();
    $fragment->appendXML('<p>Hi!</p>');
    $div->replaceWith(...$fragment->childNodes);
}

throws DOMException: Not Found Error since 8.2.6 and 8.1.19.
Probably related to #11288.

PHP Version

PHP 8.2.6, 8.1.19

Operating System

FreeBSD 12.4, Windows 10 x64

@nielsdos
Copy link
Member

They are indeed related, I'm working on a fix. Thanks for your report.

nielsdos added a commit to nielsdos/php-src that referenced this issue May 22, 2023
This replaces the implementation of before and after with one following
the spec very strictly, instead of trying to figure out the state we're
in by looking at the pointers. Also relaxes the condition on text node
copying to prevent working on a stale node pointer.
nielsdos added a commit to nielsdos/php-src that referenced this issue May 22, 2023
…placeWith

This replaces the implementation of before and after with one following
the spec very strictly, instead of trying to figure out the state we're
in by looking at the pointers. Also relaxes the condition on text node
copying to prevent working on a stale node pointer.
nielsdos added a commit to nielsdos/php-src that referenced this issue May 22, 2023
…ception with replaceWith

This replaces the implementation of before and after with one following
the spec very strictly, instead of trying to figure out the state we're
in by looking at the pointers. Also relaxes the condition on text node
copying to prevent working on a stale node pointer.
nielsdos added a commit that referenced this issue May 25, 2023
… segfaults with replaceWith

This replaces the implementation of before and after with one following
the spec very strictly, instead of trying to figure out the state we're
in by looking at the pointers. Also relaxes the condition on text node
copying to prevent working on a stale node pointer.

Closes GH-11299.
nielsdos added a commit that referenced this issue May 25, 2023
* PHP-8.1:
  Fix GH-11288 and GH-11289 and GH-11290 and GH-9142: DOMExceptions and segfaults with replaceWith
nielsdos added a commit that referenced this issue May 25, 2023
* PHP-8.2:
  Fix GH-11288 and GH-11289 and GH-11290 and GH-9142: DOMExceptions and segfaults with replaceWith
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants