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 22, 2020
1 parent 08ded7f commit 88f47ff
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
Expand Up @@ -456,15 +456,18 @@ public function makePathRelative($endPath, $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);
list($endPath, $endDriveLetter) = $stripDriveLetter($endPath);
list($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
Expand Up @@ -1115,6 +1115,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 88f47ff

Please sign in to comment.