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
Conversation
58ad30b
to
04c1efa
Compare
For 2.7? |
@@ -1094,44 +1094,46 @@ public function providePathsForMakePathRelative() | |||
$paths = array( | |||
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/src/Symfony/Component', '../'), | |||
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/src/Symfony/Component/', '../'), | |||
array('/var/lib/symfony/src/Symfony', '/var/lib/symfony/src/Symfony/Component', '../'), | |||
array('/var/lib/symfony/src/Symfony', '/var/lib/symfony/src/Symfony/Component/', '../'), | |||
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/src/Symfony/Component', '../'), |
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.
not sure why you change some tests...? Can you give more context? 🤔
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.
seems like he just removed a duplicated assertion :) missed the leading slash
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.
I've removed some dupplicate and the third point of the issue says that we should be able to dectect the trailing slash, that's why.
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.
I agree. But we should not remove the tests without the trailing slash either, just add new ones as both ways should work :-)
04c1efa
to
a69279c
Compare
rebased on 2.7 |
$endPathRemainder = implode('/', array_slice($endPathArr, $index)); | ||
|
||
// Construct $endPath from traversing to the common path, then to the remaining $endPath | ||
$relativePath = $traverser.('' !== $endPathRemainder ? $endPathRemainder.'/' : ''); | ||
if ('/' !== substr($endPath, -1)) { |
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.
@sroze So I should remove this ?
because both ways are not possible IMO.
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.
ping @sroze WDYT?
9225f6d
to
53700b6
Compare
53700b6
to
7acfd17
Compare
|
||
if ($endPath[1] !== $startPath[1]) { | ||
return ''; |
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.
Why do you return empty string here? It doesn't make sense. Maybe throw exception?
@@ -849,56 +1100,65 @@ public function providePathsForMakePathRelative() | |||
array('/usr/lib/symfony/', '/var/lib/symfony/src/Symfony/Component', '../../../../../../usr/lib/symfony/'), | |||
array('usr/lib/symfony/', 'var/lib/symfony/src/Symfony/Component', '../../../../../../usr/lib/symfony/'), | |||
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/', 'src/Symfony/'), | |||
array('/aa/bb', '/aa/bb', './'), |
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.
Why are you changing these? Some changes you have done were already tested. E.g. you change here /aa/bb
to /aa/bb/
, but that one already exists. So much changes in tests is reason why everybody is hesitant to review this. Please go through your changes in tests and only change those that are wrong, otherwise just add new ones.
@@ -370,19 +370,25 @@ public function makePathRelative($endPath, $startPath) | |||
if ('\\' === DIRECTORY_SEPARATOR) { |
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
} | ||
$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 comment
The 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);
|
||
if ($endPath[1] !== $startPath[1]) { |
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.
This will do unexpected things if paths don't contain :
. Array is returned only when it does. So when it doesn't, you are getting here second string character of relative path.
Closing as there is no more activity here. Feel free to reopen though (related issue is kept open). |
I needed to open my windows in order to test this ;).