diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index a934fd201f..6fc9b8b5f7 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -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] && 0 === $index && 1 === $depth) { + $traverser = ''; + } else { + // Repeated "../" for each level need to reach the common path + $traverser = str_repeat('../', $depth); + } $endPathRemainder = implode('/', array_slice($endPathArr, $index)); diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index cd9adee97e..b57610cb81 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -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) {