Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added separated handling of root paths
  • Loading branch information
jaytaph authored and fabpot committed Oct 13, 2015
1 parent b79dd25 commit 2709968
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Filesystem.php
Expand Up @@ -330,8 +330,13 @@ public function makePathRelative($endPath, $startPath)
// 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));

Expand Down
2 changes: 2 additions & 0 deletions Tests/FilesystemTest.php
Expand Up @@ -781,6 +781,8 @@ public function providePathsForMakePathRelative()
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) {
Expand Down

0 comments on commit 2709968

Please sign in to comment.