php-src
php-src copied to clipboard
DOMDocument::loadHTML everything after null character is not parsed
Description
The following code:
ini_set('display_errors', 1);
$d = new DOMDocument();
$html = "<html><body><span>test1</span><span>\x0</span><span>test2</span></body></html>";
$d->loadHTML($html);
$newHtml = $d->saveHTML();
echo $newHtml;
Resulted in this output:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><span>test1</span><span></span></body></html>
But I expected this output instead:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><span>test1</span><span></span><span>test2</span></body></html>
PHP Version
PHP 7.4.28, PHP 8.1.0
Operating System
WSL Docker Ubuntu
NUL bytes are neither valid for XML nor HTML. This is used by libxml2 to detect the end of the resource; there is nothing we can do about it.