php-src icon indicating copy to clipboard operation
php-src copied to clipboard

DOMDocument::loadHTML everything after null character is not parsed

Open kenylieou opened this issue 4 years ago • 1 comments

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

kenylieou avatar Feb 22 '22 14:02 kenylieou

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.

cmb69 avatar Feb 22 '22 15:02 cmb69