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