twill icon indicating copy to clipboard operation
twill copied to clipboard

Media Library upload fails when iconv does not support transliteration

Open milewski opened this issue 8 years ago • 6 comments

Hi, im trying to upload images im facing this problem:

{ "type": "ErrorException", "message": "iconv(): Wrong charset, conversion from `UTF-8' to `ASCII//TRANSLIT' is not allowed", "file": "/home/vendor/area17/twill/src/Helpers/media_library_helpers.php", "line": 28 }

image

it certainly has something to do with my environment.. as im running php inside an alpine linux docker container, i do have all necessary "laravel" dependencies installed. including the iconv extension, but yet it doesnt seem to work on an alpine linux, the hacks i have seem online seens very insecure to have set in a production server later.. this issue is all caused due to this function:

function replaceAccents($str){
  return iconv('UTF-8', 'ASCII//TRANSLIT', $str);
}

my quickly workaround is to redefine this function, perhaps consider using http://php.net/manual/en/class.transliterator.php with intl extension to do these accent replacement?

milewski avatar Nov 12 '18 07:11 milewski

Hi Rafael,

thanks for reporting this.

Indeed, iconv is not supporting this conversion on Alpine Linux :(

We will look into removing that dependency.

ifox avatar Nov 13 '18 17:11 ifox

More on this- I get a similar error on the same line. While on OSX, if i input a filename with accents or the "ñ" character, i get this exception. "type": "ErrorException", "message": "iconv(): Detected an illegal character in input string", "file"... etc

I tested the iconv() function on itself, hardcoding strings with those same characters (on a visual aspect) seem to generate no exceptions. Then I analyzed the strings giving me issues against those without issues and found that THESE are the guity characters:

́ | U+0301 | COMBINING ACUTE ACCENT

̃ | U+0303 | COMBINING TILDE

I'm guessing there's an issue in general with combining characters and the iconv() function. Since characters like "U+00F3 | LATIN SMALL LETTER O WITH ACUTE" are replaced without any issue.

tomascardenal avatar Apr 30 '19 14:04 tomascardenal

Closing this as there hasn't been any activity in a long time. If you are still looking for a fix for this, feel free to let us know.

ifox avatar Sep 02 '21 18:09 ifox

Updating this for future reference. A possible fix was shared by @FourStacks on Discord :

if (!function_exists('replaceAccents')) {
    /**
     * @param string $str
     * @return bool|string
     */
    function replaceAccents($str)
    {
        return mb_convert_encoding($str, 'ASCII', 'UTF-8');
    }
}

https://discord.com/channels/811936425858695198/811986149064441927/918893543999807590

pboivin avatar Dec 10 '21 16:12 pboivin

@pboivin , you saved my life. Mega-Thanks!

tudor-sv avatar Oct 14 '22 10:10 tudor-sv

It would be really nice if the maintainers would replace iconv with mb_convert_encoding. It's been 4 years and mbstring is a required extension for Laravel anyway.

tudor-sv avatar Oct 14 '22 10:10 tudor-sv