xref: /PHP-8.1/ext/dom/tests/gh11290.phpt (revision bffc7447)
1--TEST--
2GH-11290 (DOMElement::replaceWith causes crash)
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7$html = <<<HTML
8<!DOCTYPE HTML>
9<html>
10<body>
11    <p><span class="unwrap_me">Lorem</span><span class="unwrap_me">ipsum</span><span class="unwrap_me">dolor</span></p>
12</body>
13</html>
14HTML;
15
16$dom = new DOMDocument();
17$dom->loadHTML($html);
18
19$spans = iterator_to_array($dom->getElementsByTagName('span')->getIterator());
20foreach ($spans as $span) {
21    if ('unwrap_me' === $span->getAttribute('class')) {
22        $span->replaceWith(...$span->childNodes);
23    }
24}
25
26var_dump(str_replace("\n", "", $dom->saveHTML()));
27?>
28--EXPECT--
29string(67) "<!DOCTYPE HTML><html><body>    <p>Loremipsumdolor</p></body></html>"
30