Bug fix : from iconv to use mb_convert_encoding

More
05 Jun 2021 18:27 #3688 by sam.marko2020@gmail.com
hi all,
LangUtils.php uses iconv in a function correctEncoding
now after hours of research I found that iconv does not correctly convert the encoding resulting on language labels not shown.

the fix is
replace
```
if (function_exists('iconv')) {
$text = iconv($current_encoding, $dest_encoding . '//IGNORE', $text);
} elseif ($current_encoding == 'ISO-8859-1' && $dest_encoding == 'UTF-8') {
$text = utf8_encode($text);
}
```
to
```
if (function_exists('mb_convert_encoding')) {
$text = mb_convert_encoding($text, $dest_encoding, $current_encoding);
} elseif ($current_encoding == 'ISO-8859-1' && $dest_encoding == 'UTF-8') {
$text = utf8_encode($text);
}
```

Please Log in to join the conversation.

More
10 Jun 2021 10:06 #3694 by dende
Hi Sam,
thanks for sharing.
Could you give an example of string not correctly encoded ?

Please Log in to join the conversation.

More
11 Jun 2021 05:03 #3697 by sam.marko2020@gmail.com
Hello @dende

Actually this function was failing for each and every string conversion during installation. I don't know if this may been related to the OS I used (Alpine Linux) or it is a bug existing anywhere else. The function was failing to convert a normal Ascii characters to UTF-8.
Researching on iconv it turned out to be an issue which exists for long time and well known in the PHP community, so the recommendation was to use mb_convert_encoding instead. This worked for me. I can try having a stock installation on Ubuntu and then see if this also fails, but I thought to share it with the community who may face similar issue.

Please Log in to join the conversation.

More
09 Jul 2021 16:57 #3735 by dende
Thank you !
Will share with Dev team

Please Log in to join the conversation.

Time to create page: 0.100 seconds