xref: /PHP-8.1/ext/dom/tests/gh9142.phpt (revision bffc7447)
1--TEST--
2GH-9142 (DOMChildNode replaceWith() double-free error when replacing elements not separated by any whitespace)
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8$document = '<var>One</var><var>Two</var>';
9
10($dom = new DOMDocument('1.0', 'UTF-8'))->loadHTML($document);
11
12foreach ((new DOMXPath($dom))->query('//var') as $var) {
13    $var->replaceWith($dom->createElement('p', $var->nodeValue));
14}
15
16var_dump($dom->saveHTML());
17
18?>
19--EXPECT--
20string(154) "<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
21<html><body><p>One</p><p>Two</p></body></html>
22"
23