-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP][Filesystem] Several issues with Filesystem::makePathRelative #25169
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,19 +370,25 @@ public function makePathRelative($endPath, $startPath) | |
if ('\\' === DIRECTORY_SEPARATOR) { | ||
$endPath = str_replace('\\', '/', $endPath); | ||
$startPath = str_replace('\\', '/', $startPath); | ||
} | ||
|
||
$stripDriveLetter = function ($path) { | ||
if (strlen($path) > 2 && ':' === $path[1] && '/' === $path[2] && ctype_alpha($path[0])) { | ||
return substr($path, 2); | ||
} | ||
$stripDriveLetter = function ($path) { | ||
if (strlen($path) > 2 && ':' === $path[1] && '/' === $path[2] && ctype_alpha($path[0])) { | ||
return array(substr($path, 2), $path[0].$path[1]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't do this here, you changed what this function does - now name of function is wrong. I suggest to do something like $isAbsolutePath = function($path) {
return strlen($path) > 2 && ':' === $path[1] && '/' === $path[2] && ctype_alpha($path[0]);
}
if ($isAbsolutePath($endPath) && $isAbsolutePath($startPath) && substr($endPath, 0, 2) !== substr($startPath, 0, 2)) {
throw new \InvalidArgumentException("You can't make relative links across drives");
}
$stripDriveLetter = function ($path) (use $isAbsolutePath) {
if ($isAbsolutePath) {
return substr($path, 2);
}
return $path;
};
$endPath = $stripDriveLetter($endPath);
$startPath = $stripDriveLetter($startPath); |
||
} | ||
|
||
return $path; | ||
}; | ||
return $path; | ||
}; | ||
|
||
$endPath = $stripDriveLetter($endPath); | ||
$startPath = $stripDriveLetter($startPath); | ||
$endPath = $stripDriveLetter($endPath); | ||
$startPath = $stripDriveLetter($startPath); | ||
|
||
if ($endPath[1] !== $startPath[1]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will do unexpected things if paths don't contain |
||
return ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you return empty string here? It doesn't make sense. Maybe throw exception? |
||
} | ||
|
||
$endPath = $endPath[0]; | ||
$startPath = $startPath[0]; | ||
} | ||
// Split the paths into arrays | ||
$startPathArr = explode('/', trim($startPath, '/')); | ||
$endPathArr = explode('/', trim($endPath, '/')); | ||
|
@@ -419,7 +425,6 @@ public function makePathRelative($endPath, $startPath) | |
|
||
// Repeated "../" for each level need to reach the common path | ||
$traverser = str_repeat('../', $depth); | ||
|
||
$endPathRemainder = implode('/', array_slice($endPathArr, $index)); | ||
|
||
// Construct $endPath from traversing to the common path, then to the remaining $endPath | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment above needs to be updated. This block no longer just normalizes separators