Commit be89ff97 by Scott Tester

fixed normalizePath to keep a '.' path when necessary.

parent f02beaea
......@@ -49,13 +49,18 @@ class BaseFileHelper
$parts = [];
foreach (explode($ds, $path) as $part) {
if ($part === '..' && !empty($parts) && end($parts) !== '..') {
array_pop($parts);
} elseif ($part === '.' || $part === '' && !empty($parts)) {
if (array_pop($parts) === ".") {
$parts[] = '..';
}
} elseif (( $part === '.' || $part === '' ) && !empty($parts)) {
continue;
} else {
$parts[] = $part;
}
}
if (count($parts)>1 && $parts[0] === '.') {
array_shift($parts);
}
return implode($ds, $parts);
}
......
......@@ -369,10 +369,16 @@ class FileHelperTest extends TestCase
$this->assertEquals("..{$ds}c", FileHelper::normalizePath('//a/.\\b//..//..//../../c'));
// relative paths
$this->assertEquals(".", FileHelper::normalizePath('.'));
$this->assertEquals(".", FileHelper::normalizePath('./'));
$this->assertEquals("a", FileHelper::normalizePath('.\\a'));
$this->assertEquals("a/b", FileHelper::normalizePath('./a\\b'));
$this->assertEquals(".", FileHelper::normalizePath('./a\\../'));
$this->assertEquals("..{$ds}..{$ds}a", FileHelper::normalizePath('../..\\a'));
$this->assertEquals("..{$ds}..{$ds}a", FileHelper::normalizePath('../..\\a/../a'));
$this->assertEquals("..{$ds}..{$ds}b", FileHelper::normalizePath('../..\\a/../b'));
$this->assertEquals("..{$ds}a", FileHelper::normalizePath('./..\\a'));
$this->assertEquals("..{$ds}a", FileHelper::normalizePath('././..\\a'));
$this->assertEquals("..{$ds}a", FileHelper::normalizePath('./..\\a/../a'));
$this->assertEquals("..{$ds}b", FileHelper::normalizePath('./..\\a/../b'));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment