bug #38195 [String] improve slugger's portability accross implementations of iconv() (nicolas-grekas)
This PR was merged into the 5.1 branch.
Discussion
----------
[String] improve slugger's portability accross implementations of iconv()
| Q | A
| ------------- | ---
| Branch? | 5.1
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix #36880, fix #38060
| License | MIT
| Doc PR | -
Ping @Surfoo @edguar, can you please confirm that this fixes your issues?
Commits
-------
21e4e320b4
[String] improve slugger's portability accross implementations of iconv()
This commit is contained in:
commit
f27ca4e12d
@ -137,15 +137,15 @@ abstract class AbstractUnicodeString extends AbstractString
|
|||||||
}
|
}
|
||||||
} elseif (!\function_exists('iconv')) {
|
} elseif (!\function_exists('iconv')) {
|
||||||
$s = preg_replace('/[^\x00-\x7F]/u', '?', $s);
|
$s = preg_replace('/[^\x00-\x7F]/u', '?', $s);
|
||||||
} elseif (\ICONV_IMPL === 'glibc') {
|
|
||||||
$s = iconv('UTF-8', 'ASCII//TRANSLIT', $s);
|
|
||||||
} else {
|
} else {
|
||||||
$s = @preg_replace_callback('/[^\x00-\x7F]/u', static function ($c) {
|
$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));
|
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);
|
}, $s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user