diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index f114a2de58bc..79e842068882 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -369,10 +369,14 @@ 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; + 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 diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index 0ca2904833f2..4f7457898b27 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -840,6 +840,8 @@ public function providePathsForMakePathRelative() 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) {