Skip to content

Commit

Permalink
Fixes #16991: Removed usage of utf8_encode() from `Request::resolve…
Browse files Browse the repository at this point in the history
…PathInfo()`
  • Loading branch information
np25071984 authored and samdark committed Jan 3, 2019
1 parent 4c88805 commit a140b2b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Expand Up @@ -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)
Expand Down
22 changes: 21 additions & 1 deletion framework/web/Request.php
Expand Up @@ -922,7 +922,7 @@ protected function resolvePathInfo()
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
)*$%xs', $pathInfo)
) {
$pathInfo = utf8_encode($pathInfo);
$pathInfo = $this->utf8Encode($pathInfo);
}

$scriptUrl = $this->getScriptUrl();
Expand All @@ -944,6 +944,26 @@ protected function resolvePathInfo()
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]].
Expand Down

0 comments on commit a140b2b

Please sign in to comment.