fix handling .. and \ in path string

This commit is contained in:
Dennis Eichhorn 2021-02-12 17:59:25 +01:00
parent 8e8b40c70e
commit 122d48d493

View File

@ -109,11 +109,11 @@ final class FileUtils
*/
public static function absolute(string $origPath) : string
{
if (\realpath($origPath) !== false) {
if (\file_exists($origPath) !== false) {
return \realpath($origPath);
}
$startsWithSlash = \strpos($origPath, '/') === 0 ? '/' : '';
$startsWithSlash = \strpos($origPath, '/') === 0 || \strpos($origPath, '\\') === 0 ? '/' : '';
$path = [];
$parts = \explode('/', $origPath);
@ -123,7 +123,7 @@ final class FileUtils
continue;
}
if ($part !== '..') {
if ($part !== '..' || empty($path)) {
$path[] = $part;
} elseif (!empty($path)) {
\array_pop($path);