nette / utils

🛠 Lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.
https://doc.nette.org/utils
Other
1.98k stars 147 forks source link

TypeError in Strings::toAscii() #216

Closed strider2038 closed 4 years ago

strider2038 commented 4 years ago

Version: 3.1.1

Bug Description

iconv() https://github.com/nette/utils/blob/master/src/Utils/Strings.php#L167 returns false on some strings

TypeError: Return value of Nette\Utils\Strings::toAscii() must be of the type string, bool returned in /app/services/core/vendor/nette/utils/src/Utils/Strings.php on line 183

Steps To Reproduce

Original bug occurs when package was updated from 3.1.0 to 3.1.1 as a dependency for Easy Coding Standards library https://github.com/symplify/symplify/issues/1787

The problem occurs on Linux Alpine Docker image.

Expected Behavior

No type error

dg commented 4 years ago

On which string it returns false`

strider2038 commented 4 years ago

/app/services/core - this is project directory. May be it is platform dependent?

strider2038 commented 4 years ago

Also, there is warning

iconv(): Wrong charset, conversion from 'UTF-8' to 'ASCII//TRANSLIT//IGNORE' is not allowed
strider2038 commented 4 years ago

It seems to be a problem with Linux Alpine image as it mentioned here https://github.com/nunomaduro/phpinsights/issues/43#issuecomment-492204530

But what about processing of iconv result? Is there any alternatives to iconv()? Or maybe check for false result can be added?

$converted = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $s);
if ($converted !== false) {
    $s = $converted;
}
dg commented 4 years ago

What is value of constant ICONV_IMPL?

strider2038 commented 4 years ago

value is unknown

dg commented 4 years ago

Fixed

strider2038 commented 4 years ago

Thanks! It now works perfectly. When will be a release?

dg commented 4 years ago

I think in about a week…

strider2038 commented 4 years ago

@dg Hello! What about a release?