craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 634 forks source link

`ext-iconv` might need to be required #5759

Closed msbit closed 3 years ago

msbit commented 4 years ago

Description

Setting up a new server from scratch (without the PHP iconv extension enabled), I receive the following error when accessing /admin/login:

iconv(): Wrong charset, conversion fromutf-8' to utf-16be' is not allowed

The issue seems to be that twig/twig ends up calling iconv to convert from utf-8 to utf-16be, but the polyfill provided by symfony/polyfill-iconv doesn't have a conversion table for this.

Once I've enabled the iconv extension, the issue goes away.

Steps to reproduce

  1. Run on server with iconv extension disabled
  2. Visit /admin/login

Full stacktrace

yii\base\ErrorException: iconv(): Wrong charset, conversion from `utf-8' to `utf-16be' is not allowed in /srv/http/craft/vendor/symfony/polyfill-iconv/Iconv.php:188
Stack trace:
#0 /srv/http/craft/vendor/craftcms/cms/src/web/ErrorHandler.php(74): yii\base\ErrorHandler->handleError()
#1 [internal function]: craft\web\ErrorHandler->handleError()
#2 /srv/http/craft/vendor/symfony/polyfill-iconv/Iconv.php(188): trigger_error()
#3 /srv/http/craft/vendor/symfony/polyfill-iconv/bootstrap.php(20): Symfony\Polyfill\Iconv\Iconv::iconv()
#4 /srv/http/craft/vendor/twig/twig/src/Extension/CoreExtension.php(1004): iconv()
#5 /srv/http/craft/vendor/twig/twig/src/Extension/EscaperExtension.php(286): twig_convert_encoding()
#6 [internal function]: {closure}()
#7 /srv/http/craft/vendor/twig/twig/src/Extension/EscaperExtension.php(294): preg_replace_callback()
#8 /srv/http/craft/storage/runtime/compiled_templates/db/db2b1f951c43c23f0e0994a65206bc6adfb7531565786722562e2034a8f375dc.php(127): twig_escape_filter()
#9 /srv/http/craft/vendor/twig/twig/src/Template.php(184): __TwigTemplate_6f2190862dfcb65dda82d9187d31fffa646248d0b298ab31863aee5bb0e58f56->block_body()
#10 /srv/http/craft/storage/runtime/compiled_templates/bf/bf6c700f851510d8dc91179a0450bef45499f71401d545041ddc6ecdcd583e5c.php(75): Twig\Template->displayBlock()
#11 /srv/http/craft/vendor/twig/twig/src/Template.php(407): __TwigTemplate_a56d4fbc76b4e63c1b62e9f366eaf2b0f03ce184d26cc4bfc28911f1c8b81732->doDisplay()
#12 /srv/http/craft/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling()
#13 /srv/http/craft/storage/runtime/compiled_templates/76/768d7c85b9da0d678350deaf0d20e488effc51eec9b1e93238e3cb2f57bb7af6.php(56): Twig\Template->display()
#14 /srv/http/craft/vendor/twig/twig/src/Template.php(407): __TwigTemplate_a81746e2b294d6dd21e9a037b12b0f0978119559fcd3243efadcb9a852592101->doDisplay()
#15 /srv/http/craft/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling()
#16 /srv/http/craft/storage/runtime/compiled_templates/db/db2b1f951c43c23f0e0994a65206bc6adfb7531565786722562e2034a8f375dc.php(71): Twig\Template->display()
#17 /srv/http/craft/vendor/twig/twig/src/Template.php(407): __TwigTemplate_6f2190862dfcb65dda82d9187d31fffa646248d0b298ab31863aee5bb0e58f56->doDisplay()
#18 /srv/http/craft/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling()
#19 /srv/http/craft/vendor/twig/twig/src/Template.php(392): Twig\Template->display()
#20 /srv/http/craft/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render()
#21 /srv/http/craft/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render()
#22 /srv/http/craft/vendor/craftcms/cms/src/web/View.php(397): Twig\Environment->render()
#23 /srv/http/craft/vendor/craftcms/cms/src/web/View.php(458): craft\web\View->renderTemplate()
#24 /srv/http/craft/vendor/craftcms/cms/src/web/Controller.php(235): craft\web\View->renderPageTemplate()
#25 /srv/http/craft/vendor/craftcms/cms/src/controllers/TemplatesController.php(98): craft\web\Controller->renderTemplate()
#26 [internal function]: craft\controllers\TemplatesController->actionRender()
#27 /srv/http/craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#28 /srv/http/craft/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams()
#29 /srv/http/craft/vendor/craftcms/cms/src/web/Controller.php(178): yii\base\Controller->runAction()
#30 /srv/http/craft/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction()
#31 /srv/http/craft/vendor/craftcms/cms/src/web/Application.php(291): yii\base\Module->runAction()
#32 /srv/http/craft/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction()
#33 /srv/http/craft/vendor/craftcms/cms/src/web/Application.php(276): yii\web\Application->handleRequest()
#34 /srv/http/craft/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest()
#35 /srv/http/craft/web/index.php(21): yii\base\Application->run()
#36 {main}

Additional info

angrybrad commented 4 years ago

@msbit Guessing the Craft files on your filesystem are set to utf-16be for their character encoding?

msbit commented 4 years ago

@angrybrad not as far as I can tell; from the stacktrace the value is hardcoded:

vendor/twig/twig/src/Extension/EscaperExtension.php:286:                $char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8');
angrybrad commented 3 years ago

Looks like the Twig folks fixed this back in 2.14.0: https://github.com/twigphp/Twig/pull/3397/files

infografik commented 9 months ago

Looks like the Twig folks fixed this back in 2.14.0: https://github.com/twigphp/Twig/pull/3397/files

I love you angrybrad!

Ps. This is platonic love!