Use `mb_substr` instead of `sub_str` in order to resolve multi-language problem.

This commit is contained in:
NetPuter 2012-11-16 17:41:37 +08:00
parent d2fefa65aa
commit b48621901f
1 changed files with 15 additions and 3 deletions

View File

@ -129,7 +129,14 @@ protected static function pad($value)
*/ */
protected static function unpad($value) protected static function unpad($value)
{ {
$pad = ord($value[($length = Str::length($value)) - 1]); if (MB_STRING)
{
$pad = ord(mb_substr($value, -1, 1, Config::get('application.encoding')));
}
else
{
$pad = ord(substr($value, -1));
}
if ($pad and $pad < static::$block) if ($pad and $pad < static::$block)
{ {
@ -138,7 +145,12 @@ protected static function unpad($value)
// as the padding appears to have been changed. // as the padding appears to have been changed.
if (preg_match('/'.chr($pad).'{'.$pad.'}$/', $value)) if (preg_match('/'.chr($pad).'{'.$pad.'}$/', $value))
{ {
return substr($value, 0, $length - $pad); if (MB_STRING)
{
return mb_substr($value, 0, Str::length($value) - $pad, Config::get('application.encoding'));
}
return substr($value, 0, Str::length($value) - $pad);
} }
// If the padding characters do not match the expected padding // If the padding characters do not match the expected padding
@ -163,4 +175,4 @@ protected static function key()
return Config::get('application.key'); return Config::get('application.key');
} }
} }