diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 7bd365ecb7..a1a76c1e60 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -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) diff --git a/framework/web/Request.php b/framework/web/Request.php index c05937579a..f6c1a0de18 100644 --- a/framework/web/Request.php +++ b/framework/web/Request.php @@ -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]].