Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ffd037

Browse files
[String] throw when Alpine is used and translit fails
1 parent d285042 commit 8ffd037

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Symfony/Component/String/AbstractUnicodeString.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ public function ascii(array $rules = []): self
142142
} elseif (ICONV_IMPL === 'glibc') {
143143
$s = iconv('UTF-8', 'ASCII//TRANSLIT', $s);
144144
} else {
145-
$s = preg_replace_callback('/[^\x00-\x7F]/u', static function ($c) {
146-
$c = iconv('UTF-8', 'ASCII//IGNORE//TRANSLIT', $c[0]);
145+
$s = @preg_replace_callback('/[^\x00-\x7F]/u', static function ($c) {
146+
if ('' === $c = (string) iconv('UTF-8', 'ASCII//IGNORE//TRANSLIT', $c[0])) {
147+
throw new \LogicException(sprintf('"%s" requires a translit-able iconv implementation, try installing "gnu-libiconv" if you\'re using Alpine.', static::class));
148+
}
147149

148150
return 1 < \strlen($c) ? ltrim($c, '\'`"^~') : (\strlen($c) ? $c : '?');
149151
}, $s);

0 commit comments

Comments
 (0)