Skip to content

Commit 4a9afe9

Browse files
[String] improve slugger's portability accross implementations of iconv()
1 parent d732ad8 commit 4a9afe9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

AbstractUnicodeString.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ public function ascii(array $rules = []): self
137137
}
138138
} elseif (!\function_exists('iconv')) {
139139
$s = preg_replace('/[^\x00-\x7F]/u', '?', $s);
140-
} elseif (\ICONV_IMPL === 'glibc') {
141-
$s = iconv('UTF-8', 'ASCII//TRANSLIT', $s);
142140
} else {
143141
$s = @preg_replace_callback('/[^\x00-\x7F]/u', static function ($c) {
144-
if ('' === $c = (string) iconv('UTF-8', 'ASCII//IGNORE//TRANSLIT', $c[0])) {
142+
$c = (string) iconv('UTF-8', 'ASCII//TRANSLIT', $c[0]);
143+
144+
if ('' === $c && '' === iconv('UTF-8', 'ASCII//TRANSLIT', '²')) {
145145
throw new \LogicException(sprintf('"%s" requires a translit-able iconv implementation, try installing "gnu-libiconv" if you\'re using Alpine Linux.', static::class));
146146
}
147147

148-
return 1 < \strlen($c) ? ltrim($c, '\'`"^~') : (\strlen($c) ? $c : '?');
148+
return 1 < \strlen($c) ? ltrim($c, '\'`"^~') : ('' !== $c ? $c : '?');
149149
}, $s);
150150
}
151151
}

0 commit comments

Comments
 (0)