Fixes #17235: yii\helpers\FileHelper::normalizePath() now accepts stream wrappers

This commit is contained in:
Razvan Grigore
2019-03-29 16:26:31 +01:00
committed by Alexander Makarov
parent e9b33916b6
commit 9c37016dac
3 changed files with 13 additions and 0 deletions

View File

@ -5,6 +5,7 @@ Yii Framework 2 Change Log
------------------------
- Bug #17220: Fixed error when using non-InputWidget in active form field (s1lver)
- Bug #17235: `yii\helpers\FileHelper::normalizePath()` now accepts stream wrappers (razvanphp)
2.0.17 March 22, 2019

View File

@ -50,6 +50,9 @@ class BaseFileHelper
* - Turn multiple consecutive slashes into a single one (e.g. "/a///b/c" becomes "/a/b/c")
* - Remove ".." and "." based on their meanings (e.g. "/a/./b/../c" becomes "/a/c")
*
* Note: For registered stream wrappers, the consecutive slashes rule
* and ".."/"." translations are skipped.
*
* @param string $path the file/directory path to be normalized
* @param string $ds the directory separator to be used in the normalized result. Defaults to `DIRECTORY_SEPARATOR`.
* @return string the normalized file/directory path
@ -60,6 +63,12 @@ class BaseFileHelper
if (strpos($ds . $path, "{$ds}.") === false && strpos($path, "{$ds}{$ds}") === false) {
return $path;
}
// fix #17235 stream wrappers
foreach (stream_get_wrappers() as $protocol) {
if (strpos($path, "{$protocol}://") === 0) {
return $path;
}
}
// the path may contain ".", ".." or double slashes, need to clean them up
if (strpos($path, "{$ds}{$ds}") === 0 && $ds == '\\') {
$parts = [$ds];