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

Skip to content

Commit f70bcf6

Browse files
bug #37514 [String] throw when Alpine is used and translit fails (nicolas-grekas)
This PR was merged into the 5.0 branch. Discussion ---------- [String] throw when Alpine is used and translit fails | Q | A | ------------- | --- | Branch? | 5.0 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #37213 | License | MIT | Doc PR | - Commits ------- 98f5d50 [String] throw when Alpine is used and translit fails
2 parents d285042 + 98f5d50 commit f70bcf6

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 Linux.', static::class));
148+
}
147149

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

0 commit comments

Comments
 (0)