Skip to content

Commit

Permalink
handle paths on different drives
Browse files Browse the repository at this point in the history
  • Loading branch information
crishoj committed Apr 19, 2020
1 parent efbe752 commit ca125a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,18 @@ public function makePathRelative(string $endPath, string $startPath)
}

$stripDriveLetter = function ($path) {
if (\strlen($path) > 2 && ':' === $path[1] && '/' === $path[2] && ctype_alpha($path[0])) {
return substr($path, 2);
}

return $path;
return (\strlen($path) > 2 && ':' === $path[1] && '/' === $path[2] && ctype_alpha($path[0]))
? [substr($path, 2), $path[0]]
: [$path, null];
};

$endPath = $stripDriveLetter($endPath);
$startPath = $stripDriveLetter($startPath);
[$endPath, $endDriveLetter] = $stripDriveLetter($endPath);
[$startPath, $startDriveLetter] = $stripDriveLetter($startPath);

if ($endDriveLetter && $startDriveLetter && $endDriveLetter <> $startDriveLetter) {
// Different drives
return $endDriveLetter.':'.$endPath;
}

// Split the paths into arrays
$startPathArr = explode('/', trim($startPath, '/'));
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,7 @@ public function providePathsForMakePathRelative()
['C:/aa/bb/../../cc', 'C:/aa/../dd/..', 'cc/'],
['C:/../aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'],
['C:/../../aa/../bb/cc', 'C:/aa/dd/..', '../bb/cc/'],
['D:/aa/bb', 'C:/aa', 'D:/aa/bb'],
];

if ('\\' === \DIRECTORY_SEPARATOR) {
Expand Down

0 comments on commit ca125a9

Please sign in to comment.