Fixes #16991: Removed usage of utf8_encode() from Request::resolvePathInfo()

This commit is contained in:
Nikolay
2019-01-04 01:36:16 +03:00
committed by Alexander Makarov
parent 4c88805f85
commit a140b2b468
2 changed files with 22 additions and 1 deletions

View File

@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.16 under development
------------------------
- Bug #16991: Removed usage of `utf8_encode()` from `Request::resolvePathInfo()` (GHopperMSK)
- Bug #16974: Regular Expression Validator to include support for 'u' (UTF-8) modifier (Dzhuneyt)
- Chg #16941: Set `yii\console\controllers\MigrateController::useTablePrefix` to true as default value (GHopperMSK)
- Bug #16966: Fix ArrayExpression support in related tables (GHopperMSK)

View File

@ -922,7 +922,7 @@ class Request extends \yii\base\Request
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
)*$%xs', $pathInfo)
) {
$pathInfo = utf8_encode($pathInfo);
$pathInfo = $this->utf8Encode($pathInfo);
}
$scriptUrl = $this->getScriptUrl();
@ -944,6 +944,26 @@ class Request extends \yii\base\Request
return (string) $pathInfo;
}
/**
* Encodes an ISO-8859-1 string to UTF-8
* @param string $s
* @return string the UTF-8 translation of `s`.
* @see https://github.com/symfony/polyfill-php72/blob/master/Php72.php#L24
*/
private function utf8Encode($s)
{
$s .= $s;
$len = \strlen($s);
for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) {
switch (true) {
case $s[$i] < "\x80": $s[$j] = $s[$i]; break;
case $s[$i] < "\xC0": $s[$j] = "\xC2"; $s[++$j] = $s[$i]; break;
default: $s[$j] = "\xC3"; $s[++$j] = \chr(\ord($s[$i]) - 64); break;
}
}
return substr($s, 0, $j);
}
/**
* Returns the currently requested absolute URL.
* This is a shortcut to the concatenation of [[hostInfo]] and [[url]].