Skip to content

Commit 88f47ff

Browse files
committed
handle paths on different drives
1 parent 08ded7f commit 88f47ff

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -456,15 +456,18 @@ public function makePathRelative($endPath, $startPath)
456456
}
457457

458458
$stripDriveLetter = function ($path) {
459-
if (\strlen($path) > 2 && ':' === $path[1] && '/' === $path[2] && ctype_alpha($path[0])) {
460-
return substr($path, 2);
461-
}
462-
463-
return $path;
459+
return (\strlen($path) > 2 && ':' === $path[1] && '/' === $path[2] && ctype_alpha($path[0]))
460+
? [substr($path, 2), $path[0]]
461+
: [$path, null];
464462
};
465463

466-
$endPath = $stripDriveLetter($endPath);
467-
$startPath = $stripDriveLetter($startPath);
464+
list($endPath, $endDriveLetter) = $stripDriveLetter($endPath);
465+
list($startPath, $startDriveLetter) = $stripDriveLetter($startPath);
466+
467+
if ($endDriveLetter && $startDriveLetter && $endDriveLetter <> $startDriveLetter) {
468+
// Different drives
469+
return $endDriveLetter.':'.$endPath;
470+
}
468471

469472
// Split the paths into arrays
470473
$startPathArr = explode('/', trim($startPath, '/'));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,7 @@ public function providePathsForMakePathRelative()
11151115
['C:/aa/bb/../../cc', 'C:/aa/../dd/..', 'cc/'],
11161116
['C:/../aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'],
11171117
['C:/../../aa/../bb/cc', 'C:/aa/dd/..', '../bb/cc/'],
1118+
['D:/aa/bb', 'C:/aa', 'D:/aa/bb'],
11181119
];
11191120

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

0 commit comments

Comments
 (0)