tecnickcom / TCPDF

Official clone of PHP library to generate PDF documents and barcodes
https://tcpdf.org
Other
4.22k stars 1.52k forks source link

Undefined offset error in writeHTML() when last DOM element has display:none #496

Closed IndrekHaav closed 2 years ago

IndrekHaav commented 2 years ago

When inserting HTML into the PDF using writeHTML(), if an element in the DOM has style "display:none" and there are no other elements after it, undefined offset errors occur.

Simple test script:

<?php
require_once('tcpdf/tcpdf.php');
$pdf = new TCPDF();
$pdf->AddPage();
$html = '<p style="display:none">Foobar</p>';
$pdf->writeHTML($html);
$pdf->Output('/tmp/test.pdf', 'F');
exit;
?>

Expected behaviour: no errors.

Actual behaviour:

PHP Notice:  Undefined offset: 4 in /home/indrek/tcpdf/tcpdf.php on line 17362
PHP Notice:  Undefined offset: 4 in /home/indrek/tcpdf/tcpdf.php on line 17376
PHP Notice:  Undefined offset: 4 in /home/indrek/tcpdf/tcpdf.php on line 17427
PHP Notice:  Undefined offset: 4 in /home/indrek/tcpdf/tcpdf.php on line 17479
PHP Notice:  Undefined offset: 4 in /home/indrek/tcpdf/tcpdf.php on line 17687
PHP Notice:  Undefined offset: 4 in /home/indrek/tcpdf/tcpdf.php on line 18145
PHP Notice:  Undefined offset: 4 in /home/indrek/tcpdf/tcpdf.php on line 18435
CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.