Added separated handling of root paths

This commit is contained in:
Joshua Thijssen 2015-03-26 11:06:01 +01:00 committed by Fabien Potencier
parent d949fcc8d6
commit 7bb394e2c4
2 changed files with 9 additions and 2 deletions

View File

@ -330,8 +330,13 @@ class Filesystem
// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
$depth = count($startPathArr) - $index;
// Repeated "../" for each level need to reach the common path
$traverser = str_repeat('../', $depth);
// When we need to traverse from the start, and we are starting from a root path, don't add '../'
if ($startPath[0] == '/' && $index == 0 && $depth == 1) {
$traverser = '';
} else {
// Repeated "../" for each level need to reach the common path
$traverser = str_repeat('../', $depth);
}
$endPathRemainder = implode('/', array_slice($endPathArr, $index));

View File

@ -781,6 +781,8 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase
array('/a/aab/bb', '/a/aa/', '../aab/bb/'),
array('/a/aab/bb/', '/a/aa', '../aab/bb/'),
array('/a/aab/bb/', '/a/aa/', '../aab/bb/'),
array('/a/aab/bb/', '/', 'a/aab/bb/'),
array('/a/aab/bb/', '/b/aab', '../../a/aab/bb/'),
);
if ('\\' === DIRECTORY_SEPARATOR) {