Skip to content

Conversation

@shyim
Copy link

@shyim shyim commented Apr 10, 2024

$encoding is hard-code to ISO-8859-1

converting utf-8 to ISO-8859-1 throws a warning.
https://3v4l.org/veXqX

on newer systems even a exception:

PHP Fatal error:  Uncaught BaconQrCode\Exception\WriterException: Could not encode content to ISO-8859-1 in /workspace/BaconQrCode/src/Encoder/Encoder.php:619
Stack trace:
#0 /workspace/BaconQrCode/src/Encoder/Encoder.php(532): BaconQrCode\Encoder\Encoder::append8BitBytes()
#1 /workspace/BaconQrCode/src/Encoder/Encoder.php(82): BaconQrCode\Encoder\Encoder::appendBytes()
#2 /workspace/BaconQrCode/src/Writer.php(46): BaconQrCode\Encoder\Encoder::encode()
#3 /workspace/BaconQrCode/src/Writer.php(61): BaconQrCode\Writer->writeString()
#4 /workspace/BaconQrCode/test.php(16): BaconQrCode\Writer->writeFile()

@DASPRiD
Copy link
Member

DASPRiD commented Apr 10, 2024

That would remove that feature completely, which is not desired. I can't find much information about this online, do you have any source for the reason of this issue?

@shyim
Copy link
Author

shyim commented Apr 10, 2024

You mean converting utf-8 to ISO-8859-1 ? I have no clue, it throws a fatal error in my docker image 😅

@shyim
Copy link
Author

shyim commented Apr 10, 2024

Maybe use mbstring instead of iconv here?
https://3v4l.org/2NQjo#v8.2.18

seems to work 🤔

@shyim
Copy link
Author

shyim commented Apr 10, 2024

If you don't want require mbstring directly, we can use https://packagist.org/packages/symfony/polyfill-mbstring

@DASPRiD
Copy link
Member

DASPRiD commented Apr 10, 2024

Would mbstring introduce a new dependency or is that built into PHP by now?

@shyim
Copy link
Author

shyim commented Apr 10, 2024

mbstring is a php extension by php itself, but not installed by default. When it's not installed, we can use the polyfill which is kinda the same but without having the need to install it

@DASPRiD
Copy link
Member

DASPRiD commented Apr 18, 2024

I'd like to hear some input from some other people on this topic, before we continue.

@williamdes
Copy link
Contributor

mbstring is a php extension by php itself, but not installed by default. When it's not installed, we can use the polyfill which is kinda the same but without having the need to install it

Not installed by default on Debian for example ?
All this years iconv seems for me not as good as mbstring

private static function append8BitBytes(string $content, BitArray $bits, string $encoding) : void
private static function append8BitBytes(string $bytes, BitArray $bits) : void
{
$bytes = @iconv('utf-8', $encoding, $content);
Copy link
Contributor

Choose a reason for hiding this comment

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

this could be done only if mbstring is not present ?

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