Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3a29c1d

Browse files
committed
Do not strip the beginning of relative paths, only drive letters
1 parent fc745f4 commit 3a29c1d

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,18 +358,20 @@ public function makePathRelative($endPath, $startPath)
358358
$startPath = str_replace('\\', '/', $startPath);
359359
}
360360

361+
$stripDriveLetter = function($path) {
362+
if (strlen($path) > 2 && substr($path, 1, 2) === ':/' && ctype_alpha($path[0])) {
363+
return substr($path, 2);
364+
}
365+
return $path;
366+
};
367+
368+
$endPath = $stripDriveLetter($endPath);
369+
$startPath = $stripDriveLetter($startPath);
370+
361371
// Split the paths into arrays
362372
$startPathArr = explode('/', trim($startPath, '/'));
363373
$endPathArr = explode('/', trim($endPath, '/'));
364374

365-
if ('/' !== $startPath[0]) {
366-
array_shift($startPathArr);
367-
}
368-
369-
if ('/' !== $endPath[0]) {
370-
array_shift($endPathArr);
371-
}
372-
373375
$normalizePathArray = function ($pathSegments) {
374376
$result = array();
375377

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ public function providePathsForMakePathRelative()
847847
array('/var/lib/symfony/src/Symfony', '/var/lib/symfony/src/Symfony/Component/', '../'),
848848
array('var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component', '../../../'),
849849
array('/usr/lib/symfony/', '/var/lib/symfony/src/Symfony/Component', '../../../../../../usr/lib/symfony/'),
850+
array('usr/lib/symfony/', 'var/lib/symfony/src/Symfony/Component', '../../../../../../usr/lib/symfony/'),
850851
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/', 'src/Symfony/'),
851852
array('/aa/bb', '/aa/bb', './'),
852853
array('/aa/bb', '/aa/bb/', './'),
@@ -878,6 +879,8 @@ public function providePathsForMakePathRelative()
878879
array('C:/aa/bb/../../cc', 'C:/aa/../dd/..', 'cc/'),
879880
array('C:/../aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'),
880881
array('C:/../../aa/../bb/cc', 'C:/aa/dd/..', '../bb/cc/'),
882+
array('aa/bb', 'aa/cc', '../bb/'),
883+
array('aa/cc', 'bb/cc', '../../aa/cc/'),
881884
);
882885

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

0 commit comments

Comments
 (0)