Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show correct error on incorrect encoding #594

Closed
wants to merge 1 commit into from

Conversation

rubo77
Copy link
Contributor

@rubo77 rubo77 commented Mar 7, 2023

Signed-off-by: Ruben Barkow-Kuder github@r.z11.de

E.G if you try this:

$pdf->multiCell(0, 4, 'Some non-UTF-8 text: '.unhtmlentities('ü'), 0, 'L');

You will get this error on PHP 8.1:

Fatal error: Uncaught ValueError: max(): Argument #1 ($value) must contain at least one element in tcpdf.php:6412

This commit will show a useful error with the causing string

@CLAassistant
Copy link

CLAassistant commented Mar 7, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@williamdes williamdes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not feel like the right fix 🤔

@rubo77
Copy link
Contributor Author

rubo77 commented Mar 7, 2023

The problem is, that this line:

// get array of unicode values
$chars = TCPDF_FONTS::UTF8StringToArray($s, $this->isunicode, $this->CurrentFont);

sets $char to an empty array if $s contains non-utf8 characters

UTF8StringToArray() calls this line:

$chars = TCPDF_STATIC::pregSplit('//','u', $str, -1, PREG_SPLIT_NO_EMPTY);

which creates the empty array()

Signed-off-by: Ruben Barkow-Kuder <github@r.z11.de>
@rubo77
Copy link
Contributor Author

rubo77 commented Mar 7, 2023

I moved the error code generation into the function UTF8StringToArray().

The problem always was before PHP8: if you create

new TCPDF(pageFormat, $unit, $pageSize, $isunicode)

with $isunicode== true, and there are non-utf8- characters in a string, the PDF generation was just ignoring this whole Cell for that string, leaving it empty without errror warning.

This should enlighten users a bit, what is going wrong then

@rubo77
Copy link
Contributor Author

rubo77 commented Apr 19, 2023

Maybe we should add and !empty($str) ?

if(empty($chars)){
die('TCPDF Error: Incorrect encoding: '.$str);
}else{
$carr = array_map(array('TCPDF_FONTS', 'uniord'), $chars);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change this for PHP 8.2 compat, see #633 (#632)

@rubo77
Copy link
Contributor Author

rubo77 commented Aug 3, 2023

Please resolve this someone else. Sorry I don't have the time any more

@rubo77 rubo77 closed this Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants