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);