From cd3206c5cba85bdef04ac1c0d015543064bf1ee8 Mon Sep 17 00:00:00 2001 From: Muhammed Akbulut Date: Fri, 29 Jul 2016 16:40:15 +0200 Subject: [PATCH] fixed Filesystem:makePathRelative and added 2 more testcases --- src/Symfony/Component/Filesystem/Filesystem.php | 8 ++++++-- src/Symfony/Component/Filesystem/Tests/FilesystemTest.php | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) 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) {