[php-src] Issue #12057: Tag level error closing div in DOMDocument::loadHtml

From: Date: Sun, 27 Aug 2023 11:14:18 +0000
Subject: [php-src] Issue #12057: Tag level error closing div in DOMDocument::loadHtml
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245259@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/12057 Author: crucifyer ### Description The following code: ```php <?php $dom = new DOMDocument(); $dom->loadHTML(file_get_contents('test.html'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); echo $dom->saveHTML(); ``` test.html ```html <div class="aaa"> <iframe src="about:blank"></iframe> <input class="bbb" type="button" value="bbb"> </div> <div id="ccc"> <div class="ddd"> &nbsp; </div> </div> ``` Resulted in this output: ```html <div class="aaa"> <iframe src="about:blank"></iframe> <input class="bbb" type="button" value="bbb"> <div id="ccc"> <div class="ddd"> &nbsp; </div> </div></div><!-- first div is incorrectly closed here --> ``` But I expected this output instead: ```html <div class="aaa"> <iframe src="about:blank"></iframe> <input class="bbb" type="button" value="bbb"> </div><!-- here --> <div id="ccc"> <div class="ddd"> &nbsp; </div> </div> ``` The bug occurs regardless of PHP version, and my guess is that the depth calculation is buggy when there is no wrapper. The bug does not occur if there is a wrapping tag, either by wrapping the whole thing in a div or by removing the LIBXML_HTML_NOIMPLIED option. thank you. ### PHP Version php 8.1.2 ### Operating System ubuntu 22.04

« previous php.bugs (#245259) next »