Skip to content
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

Fix Path#join to convert argument path to base kind #12033

Merged

Conversation

straight-shoota
Copy link
Member

When the argument to Path#join is a different kind than self (windows vs. posix path), the argument needs to be converted to the base kind. This did happen only for joining a windows path to a posix path, but not the other way around. This only became necessary with #11847. Previously, it would've been a no-op.

This patch makes sure to always convert the parameter path when it doesn't match the base kind.

The PR is applied on top of #12032 which is required for the correct implementation of Path#join(Enumerable) based on Path#join(String | Path).

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:files labels Apr 27, 2022
@straight-shoota straight-shoota deleted the branch crystal-lang:master April 29, 2022 15:21
@straight-shoota straight-shoota changed the base branch from fix/path-join to master May 11, 2022 18:03
@straight-shoota straight-shoota marked this pull request as ready for review May 11, 2022 18:03
end

new_instance new_name
parts.reduce(self) { |path, part| path.join(part) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will bring a little penalty to those that do not need conversion, since it will create an allocation per path. I don't know how important this difference might be though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need correctness over performance. This can be optimized later, but it's not critical to optimize.

@beta-ziliani beta-ziliani added this to the 1.5.0 milestone May 20, 2022
@straight-shoota straight-shoota merged commit 86927ef into crystal-lang:master May 23, 2022
@straight-shoota straight-shoota deleted the fix/path-join-conversion branch May 23, 2022 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants