8000 fixed Filesystem:makePathRelative and added 2 more testcases · symfony/symfony@cd3206c · GitHub
[go: up one dir, main page]

Skip to content

Commit cd3206c

Browse files
Muhammed Akbulutfabpot
Muhammed Akbulut
authored andcommitted
fixed Filesystem:makePathRelative and added 2 more testcases
1 parent 8d218e7 commit cd3206c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,14 @@ public function makePathRelative($endPath, $startPath)
369369
}
370370

371371
// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
372-
$depth = count($startPathArr) - $index;
372+
if (count($startPathArr) === 1 && $startPathArr[0] === '') {
373+
$depth = 0;
374+
} else {
375+
$depth = count($startPathArr) - $index;
376+
}
373377

374378
// When we need to traverse from the start, and we are starting from a root path, don't add '../'
375-
if ('/' === $startPath[0] && 0 === $index && 1 === $depth) {
379+
if ('/' === $startPath[0] && 0 === $index && 0 === $depth) {
376380
$traverser = '';
377381
} else {
378382
// Repeated "../" for each level need to reach the common path

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,8 @@ public function providePathsForMakePathRelative()
840840
array('/a/aab/bb/', '/a/aa/', '../aab/bb/'),
841841
array('/a/aab/bb/', '/', 'a/aab/bb/'),
842842
array('/a/aab/bb/', '/b/aab', '../../a/aab/bb/'),
843+
array('/aab/bb', '/aa', '../aab/bb/'),
844+
array('/aab', '/aa', '../aab/'),
843845
);
844846

845847
if ('\\' === DIRECTORY_SEPARATOR) {

0 commit comments

Comments
 (0)
0