@@ -455,37 +455,36 @@ public function makePathRelative($endPath, $startPath)
455
455
$ startPath = str_replace ('\\' , '/ ' , $ startPath );
456
456
}
457
457
458
- $ 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 ;
458
+ $ splitDriveLetter = function ($ path ) {
459
+ return (\strlen ($ path ) > 2 && ': ' === $ path [1 ] && '/ ' === $ path [2 ] && ctype_alpha ($ path [0 ]))
460
+ ? [substr ($ path , 2 ), strtoupper ($ path [0 ])]
461
+ : [$ path , null ];
464
462
};
465
463
466
- $ endPath = $ stripDriveLetter ($ endPath );
467
- $ startPath = $ stripDriveLetter ($ startPath );
468
-
469
- // Split the paths into arrays
470
- $ startPathArr = explode ('/ ' , trim ($ startPath , '/ ' ));
471
- $ endPathArr = explode ('/ ' , trim ($ endPath , '/ ' ));
472
-
473
- $ normalizePathArray = function ($ pathSegments , $ absolute ) {
464
+ $ splitPath = function ($ path , $ absolute ) {
474
465
$ result = [];
475
466
476
- foreach ($ pathSegments as $ segment ) {
467
+ foreach (explode ( ' / ' , trim ( $ path , ' / ' )) as $ segment ) {
477
468
if ('.. ' === $ segment && ($ absolute || \count ($ result ))) {
478
469
array_pop ($ result );
479
- } elseif ('. ' !== $ segment ) {
470
+ } elseif ('. ' !== $ segment && '' !== $ segment ) {
480
471
$ result [] = $ segment ;
481
472
}
482
473
}
483
474
484
475
return $ result ;
485
476
};
486
477
487
- $ startPathArr = $ normalizePathArray ($ startPathArr , static ::isAbsolutePath ($ startPath ));
488
- $ endPathArr = $ normalizePathArray ($ endPathArr , static ::isAbsolutePath ($ endPath ));
478
+ list ($ endPath , $ endDriveLetter ) = $ splitDriveLetter ($ endPath );
479
+ list ($ startPath , $ startDriveLetter ) = $ splitDriveLetter ($ startPath );
480
+
481
+ $ startPathArr = $ splitPath ($ startPath , static ::isAbsolutePath ($ startPath ));
482
+ $ endPathArr = $ splitPath ($ endPath , static ::isAbsolutePath ($ endPath ));
483
+
484
+ if ($ endDriveLetter && $ startDriveLetter && $ endDriveLetter != $ startDriveLetter ) {
485
+ // End path is on another drive, so no relative path exists
486
+ return $ endDriveLetter .':/ ' .($ endPathArr ? implode ('/ ' , $ endPathArr ).'/ ' : '' );
487
+ }
489
488
490
489
// Find for which directory the common path stops
491
490
$ index = 0 ;
0 commit comments