Bug #72288 [Opn]: Lines longer than 1000 characters break DOMDocument::loadHTML()

From: Date: Mon, 30 May 2016 09:28:39 +0000
Subject: Bug #72288 [Opn]: Lines longer than 1000 characters break DOMDocument::loadHTML()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201335@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72288&edit=1 ID: 72288 User updated by: maciej at klepaczewski dot com Reported by: maciej at klepaczewski dot com Summary: Lines longer than 1000 characters break DOMDocument::loadHTML() Status: Open Type: Bug Package: DOM XML related Operating System: Windows, Linux PHP Version: 5.6.22 Block user comment: N Private report: N New Comment: One thing I forgot to mention is that the <body> and its attributes are replaced with empty <body>. So if original body has <body class="page"> then after the warning it's replaced with vanilla <body> tag. Improved test script showing this behavior: ----- <?php error_reporting(E_ALL); $html = <<<HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da" lang="da"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Test</title> <!--placeholder--> </head> <body class="page"> </body> </html> HTML; echo "==== < 1000 spaces in head===\n"; $x = new DOMDocument(); $x->loadHTML(str_replace('<!--placeholder-->', str_repeat(' ', 995), $html)); echo $x->saveHTML(); echo "==== 1000 spaces in head===\n"; $y = new DOMDocument(); $y->loadHTML(str_replace('<!--placeholder-->', str_repeat(' ', 1000), $html)); echo $y->saveHTML(); Previous Comments: ------------------------------------------------------------------------ [2016-05-30 09:13:05] maciej at klepaczewski dot com Description: ------------ When a single line contains more than 1000 characters (might depend on EOL format) DOMDocument::loadHTML() errs with message similar to: ===== Warning: DOMDocument::loadHTML(): Unexpected end tag : head in Entity, line: 7 in test.php on line 4 Warning: DOMDocument::loadHTML(): htmlParseStartTag: misplaced <body> tag in Entity, line: 8 in test.php on line 4 ===== Test script: --------------- <?php error_reporting(E_ALL); $html = <<<HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da" lang="da"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Test</title> <!--placeholder--> </head> <body> </body> </html> HTML; echo "==== < 1000 spaces in head===\n"; $x = new DOMDocument(); $x->loadHTML(str_replace('<!--placeholder-->', str_repeat(' ', 995), $html)); echo "==== 1000 spaces in head===\n"; $y = new DOMDocument(); $y->loadHTML(str_replace('<!--placeholder-->', str_repeat(' ', 1000), $html)); Expected result: ---------------- ==== < 1000 spaces in head=== ==== 1000 spaces in head=== Actual result: -------------- ==== < 1000 spaces in head=== ==== 1000 spaces in head=== Warning: DOMDocument::loadHTML(): Unexpected end tag : head in Entity, line: 7 in test.php on line 20 Warning: DOMDocument::loadHTML(): htmlParseStartTag: misplaced <body> tag in Entity, line: 8 in test.php on line 20 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72288&edit=1

« previous php.bugs (#201335) next »