Skip to content

Commit 89634a0

Browse files
Merge branch '5.0'
* 5.0: (26 commits) [Filesystem] Handle paths on different drives [WebProfiler] Do not add src-elem CSP directives if they do not exist [Yaml] fix parse error when unindented collections contain a comment Execute docker dependent tests with github actions Update exception.html.php [3.4][Inflector] Improve testSingularize() argument name [Inflector] Fix testPluralize() arguments names [PhpUnitBridge] fix PHP 5.3 compat again Skip validation when email is an empty object fix sr_Latn translation [Validator] fix lazy property usage. Fix annotation [Debug][ErrorHandler] cleanup phpunit.xml.dist files [Translation] Fix for translation:update command updating ICU messages [PhpUnitBridge] fix compat with PHP 5.3 bumped Symfony version to 5.0.9 updated VERSION for 5.0.8 updated CHANGELOG for 5.0.8 bumped Symfony version to 4.4.9 updated VERSION for 4.4.8 ...
2 parents b3ee7d5 + a628f26 commit 89634a0

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

Filesystem.php

+17-18
Original file line numberDiff line numberDiff line change
@@ -434,37 +434,36 @@ public function makePathRelative(string $endPath, string $startPath)
434434
$startPath = str_replace('\\', '/', $startPath);
435435
}
436436

437-
$stripDriveLetter = function ($path) {
438-
if (\strlen($path) > 2 && ':' === $path[1] && '/' === $path[2] && ctype_alpha($path[0])) {
439-
return substr($path, 2);
440-
}
441-
442-
return $path;
437+
$splitDriveLetter = function ($path) {
438+
return (\strlen($path) > 2 && ':' === $path[1] && '/' === $path[2] && ctype_alpha($path[0]))
439+
? [substr($path, 2), strtoupper($path[0])]
440+
: [$path, null];
443441
};
444442

445-
$endPath = $stripDriveLetter($endPath);
446-
$startPath = $stripDriveLetter($startPath);
447-
448-
// Split the paths into arrays
449-
$startPathArr = explode('/', trim($startPath, '/'));
450-
$endPathArr = explode('/', trim($endPath, '/'));
451-
452-
$normalizePathArray = function ($pathSegments) {
443+
$splitPath = function ($path) {
453444
$result = [];
454445

455-
foreach ($pathSegments as $segment) {
446+
foreach (explode('/', trim($path, '/')) as $segment) {
456447
if ('..' === $segment) {
457448
array_pop($result);
458-
} elseif ('.' !== $segment) {
449+
} elseif ('.' !== $segment && '' !== $segment) {
459450
$result[] = $segment;
460451
}
461452
}
462453

463454
return $result;
464455
};
465456

466-
$startPathArr = $normalizePathArray($startPathArr);
467-
$endPathArr = $normalizePathArray($endPathArr);
457+
list($endPath, $endDriveLetter) = $splitDriveLetter($endPath);
458+
list($startPath, $startDriveLetter) = $splitDriveLetter($startPath);
459+
460+
$startPathArr = $splitPath($startPath);
461+
$endPathArr = $splitPath($endPath);
462+
463+
if ($endDriveLetter && $startDriveLetter && $endDriveLetter != $startDriveLetter) {
464+
// End path is on another drive, so no relative path exists
465+
return $endDriveLetter.':/'.($endPathArr ? implode('/', $endPathArr).'/' : '');
466+
}
468467

469468
// Find for which directory the common path stops
470469
$index = 0;

Tests/FilesystemTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -1151,10 +1151,14 @@ public function providePathsForMakePathRelative()
11511151
['/../aa/bb/cc', '/aa/dd/..', 'bb/cc/'],
11521152
['/../../aa/../bb/cc', '/aa/dd/..', '../bb/cc/'],
11531153
['C:/aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'],
1154+
['C:/aa/bb/cc', 'c:/aa/dd/..', 'bb/cc/'],
11541155
['c:/aa/../bb/cc', 'c:/aa/dd/..', '../bb/cc/'],
11551156
['C:/aa/bb/../../cc', 'C:/aa/../dd/..', 'cc/'],
11561157
['C:/../aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'],
11571158
['C:/../../aa/../bb/cc', 'C:/aa/dd/..', '../bb/cc/'],
1159+
['D:/', 'C:/aa/../bb/cc', 'D:/'],
1160+
['D:/aa/bb', 'C:/aa', 'D:/aa/bb/'],
1161+
['D:/../../aa/../bb/cc', 'C:/aa/dd/..', 'D:/bb/cc/'],
11581162
];
11591163

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

0 commit comments

Comments
 (0)