Skip to content

Commit

Permalink
Strings::toAscii() removes combining character [Closes #614]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jul 30, 2012
1 parent 077d99b commit 18023a0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Nette/Utils/Strings.php
Expand Up @@ -163,7 +163,7 @@ public static function normalize($s)
*/
public static function toAscii($s)
{
$s = preg_replace('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{10FFFF}]#u', '', $s);
$s = preg_replace('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{2FF}\x{370}-\x{10FFFF}]#u', '', $s);
$s = strtr($s, '`\'"^~', "\x01\x02\x03\x04\x05");
if (ICONV_IMPL === 'glibc') {
$s = @iconv('UTF-8', 'WINDOWS-1250//TRANSLIT', $s); // intentionally @
Expand Down
1 change: 1 addition & 0 deletions tests/Nette/Utils/Strings.toAscii().phpt
Expand Up @@ -17,4 +17,5 @@ require __DIR__ . '/../bootstrap.php';


Assert::same( 'ZLUTOUCKY KUN oooo', Strings::toAscii("\xc5\xbdLU\xc5\xa4OU\xc4\x8cK\xc3\x9d K\xc5\xae\xc5\x87 \xc3\xb6\xc5\x91\xc3\xb4o") ); // 沤LU扭OU膶K脻 K女艊 枚艖么o
Assert::same( 'Zlutoucky kun', Strings::toAscii("Z\xCC\x8Clut\xCC\x8Couc\xCC\x8Cky\xCC\x81 ku\xCC\x8An\xCC\x8C") ); // 沤lu钮ou膷k媒 k暖艌 with combining characters
Assert::same( 'Z `\'"^~', Strings::toAscii("\xc5\xbd `'\"^~") );

0 comments on commit 18023a0

Please sign in to comment.