-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Filesystem] Fix makePathRelative when the original path does not end with a slash #40051
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
Conversation
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
d1ca84c
to
38056e4
Compare
38056e4
to
4a18f94
Compare
I think the check is worth it. is_dir is cached, so it won't slow down things much. |
You mean we will be checking the directory and adding a slash regardless of the input string? I am assuming the method will still have output when a path not exists, then it can produce different output on subsequent run or different state of the filesystem: $filesystem =new Symfony\Component\Filesystem\Filesystem();
$relative = $filesystem->makePathRelative('/path/to/project/resources', '/path/to/project');
if ($filesystem->exists('/path/to/project/resources')) {
mkdir('/path/to/project/resources' );
}
echo $relative . PHP_EOL;
// -> '/path/to/project/resources' if dir not exist
// -> '/path/to/project/resources/' if dir exist (or second run) I believe it will create more problems than we currently have. |
I'm closing here because I think this can create troubles in existing codebases. |
I understand the reasons. Given the if (!str_ends_with($endPath, '/')) {
$relativePath = rtrim($relativePath, '/');
} |
This needs to be definitely fixed, when a non-dir path is given (path not ending with |
+1, I use this function to make a path to a stylesheet file (e.g. |
@nicolas-grekas Sensible fix like https://github.com/atk4/ui/blob/8f7a986c629a0adf3342c6d285bbef613fe52095/src/App.php#L655-L658 works /w current/buggy Symfony and /w this PR/fixed Symfony so fixing it should be fine as long as the developer was aware of this issue and counted with the possibility to be fixed in the future. For me, it is clearly a bug in Symfony and it should be fixed sooner or later. Can you please reconsider this PR, if not for 4.4, can it be integrated into 6.x? |
Maintain the path format after making relative.
History:
PR #4842 added a slash to the function output. According to the original explanation, "[...]to ensure all returned paths end with /."
Reason for change:
There is no need to add a slash, not even for operation upon directories. Maintaining the input format should enough for all file manipulation (symlink, copy, unset, etc.). There is a slight chance to introduce a break, but only if the path further altered after it changed to the relative. One possible mitigation would be to checking the input; it is a file or directory. But, the function in the current form does not access the filesystem. Adding an extra check will significantly slow it down and produce two different results when the
$endPath
exists, a directory, and the input does not have a trailing slash.Test altered to reflect the changes.