Commit 78a8694e by Carsten Brandt

file helper did not preserve relative paths

parent e3463303
...@@ -48,7 +48,7 @@ class BaseFileHelper ...@@ -48,7 +48,7 @@ class BaseFileHelper
// the path may contain ".", ".." or double slashes, need to clean them up // the path may contain ".", ".." or double slashes, need to clean them up
$parts = []; $parts = [];
foreach (explode($ds, $path) as $part) { foreach (explode($ds, $path) as $part) {
if ($part === '..' && !empty($parts)) { if ($part === '..' && !empty($parts) && end($parts) !== '..') {
array_pop($parts); array_pop($parts);
} elseif ($part === '.' || $part === '' && !empty($parts)) { } elseif ($part === '.' || $part === '' && !empty($parts)) {
continue; continue;
......
...@@ -367,6 +367,14 @@ class FileHelperTest extends TestCase ...@@ -367,6 +367,14 @@ class FileHelperTest extends TestCase
$this->assertEquals("{$ds}c", FileHelper::normalizePath('/a/.\\b//../../c')); $this->assertEquals("{$ds}c", FileHelper::normalizePath('/a/.\\b//../../c'));
$this->assertEquals("c", FileHelper::normalizePath('/a/.\\b/../..//../c')); $this->assertEquals("c", FileHelper::normalizePath('/a/.\\b/../..//../c'));
$this->assertEquals("..{$ds}c", FileHelper::normalizePath('//a/.\\b//..//..//../../c')); $this->assertEquals("..{$ds}c", FileHelper::normalizePath('//a/.\\b//..//..//../../c'));
// relative paths
$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/../a'));
$this->assertEquals("..{$ds}b", FileHelper::normalizePath('./..\\a/../b'));
} }
public function testLocalizedDirectory() public function testLocalizedDirectory()
......
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