From 98f5d509451a9a84783ccfccb9d8c37850b1fff9 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 7 Jul 2020 18:09:42 +0200 Subject: [PATCH] [String] throw when Alpine is used and translit fails --- src/Symfony/Component/String/AbstractUnicodeString.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/String/AbstractUnicodeString.php b/src/Symfony/Component/String/AbstractUnicodeString.php index 9beafe57ebc26..2d29ce91371a7 100644 --- a/src/Symfony/Component/String/AbstractUnicodeString.php +++ b/src/Symfony/Component/String/AbstractUnicodeString.php @@ -142,8 +142,10 @@ public function ascii(array $rules = []): self } elseif (ICONV_IMPL === 'glibc') { $s = iconv('UTF-8', 'ASCII//TRANSLIT', $s); } else { - $s = preg_replace_callback('/[^\x00-\x7F]/u', static function ($c) { - $c = iconv('UTF-8', 'ASCII//IGNORE//TRANSLIT', $c[0]); + $s = @preg_replace_callback('/[^\x00-\x7F]/u', static function ($c) { + if ('' === $c = (string) iconv('UTF-8', 'ASCII//IGNORE//TRANSLIT', $c[0])) { + throw new \LogicException(sprintf('"%s" requires a translit-able iconv implementation, try installing "gnu-libiconv" if you\'re using Alpine Linux.', static::class)); + } return 1 < \strlen($c) ? ltrim($c, '\'`"^~') : (\strlen($c) ? $c : '?'); }, $s);