fixed Filesystem:makePathRelative and added 2 more testcases

This commit is contained in:
Muhammed Akbulut 2016-07-29 16:40:15 +02:00 committed by Fabien Potencier
parent 8d218e7f50
commit cd3206c5cb
2 changed files with 8 additions and 2 deletions

View File

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

View File

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