Shopware 6: Notice: iconv(): Wrong charset, conversion from `utf-32le‘ to `utf-8′ is not allowed

Start theme compilation
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:53 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:53 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]
12:32:54 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]

 ! [NOTE] Took 9.129729 seconds

We are launching another shopware 6 soon, but the server we are running on for some reason is throwing the above error:

12:32:49 WARNING   [php] Notice: iconv(): Wrong charset, conversion from `utf-32le' to `utf-8' is not allowed ["exception" => ErrorException { …}]

There is a thread on the shopware forum which helped a lot to identify the problem, but unfortunately my impression is, that the discussion is between non-techies, at least I don’t see an attempt of an explanation.

The problem

The problem is, that for some reason the function/library iconv sometimes isn’t able to convert a file which is UTF32-LE to an UTF-8 file. Don’t ask me, what that in detail means, but what I get is: „We have an encoding problem“ and on one system it works and on one it doesn’t.

I couldn’t identify a difference between our staging system and the live system (which has the problem). PHP version is the same, iconv version is the same, setting seem to be the same. LC_* on bash is on one system de_DE.UTF-8 and on the other en_US.UTF-8 and setting it explicitly didn’T help.

My solution

Thanks to the thread I already had a half-way solution, by not using iconv but mb_convert_encoding.

So we need to change line 91 in vendor/sabberworm/php-css-parser/lib/Sabberworm/CSS/Parsing/ParserState.php

// from
return iconv('utf-32le', $this->sCharset, $sUtf32);
// to
mb_convert_encoding($sUtf32 , $this->sCharset , 'UTF-32LE');

But please, don’t hack your vendor folder. It is the first step straight into hell. Instead use a composer module like cweagans/composer-patches which can patch your vendor folder after deployment.

Next step: Pull request to sabberworm/php-css-parser

Kommentar verfassen