From 21e4e320b4478b36f3a220a83773176437f9b454 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 15 Sep 2020 12:20:00 +0200 Subject: [PATCH] [String] improve slugger's portability accross implementations of iconv() --- src/Symfony/Component/String/AbstractUnicodeString.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/String/AbstractUnicodeString.php b/src/Symfony/Component/String/AbstractUnicodeString.php index 258407959c..0725e1e515 100644 --- a/src/Symfony/Component/String/AbstractUnicodeString.php +++ b/src/Symfony/Component/String/AbstractUnicodeString.php @@ -137,15 +137,15 @@ abstract class AbstractUnicodeString extends AbstractString } } elseif (!\function_exists('iconv')) { $s = preg_replace('/[^\x00-\x7F]/u', '?', $s); - } elseif (\ICONV_IMPL === 'glibc') { - $s = iconv('UTF-8', 'ASCII//TRANSLIT', $s); } else { $s = @preg_replace_callback('/[^\x00-\x7F]/u', static function ($c) { - if ('' === $c = (string) iconv('UTF-8', 'ASCII//IGNORE//TRANSLIT', $c[0])) { + $c = (string) iconv('UTF-8', 'ASCII//TRANSLIT', $c[0]); + + if ('' === $c && '' === iconv('UTF-8', 'ASCII//TRANSLIT', '²')) { 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 : '?'); + return 1 < \strlen($c) ? ltrim($c, '\'`"^~') : ('' !== $c ? $c : '?'); }, $s); } }