Skip to content

Commit

Permalink
Fix Path#join to convert argument path to base kind (#12033)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored May 23, 2022
1 parent 04f1c5a commit 86927ef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions spec/std/path_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ describe Path do
Path.new(Path.new("foo"), "bar").should eq Path.new("foo", "bar")
Path.new(Path.posix("foo"), "bar").should eq Path.new("foo", "bar")
Path.new(Path.windows("foo"), "bar").should eq Path.new("foo", "bar")

# implicit conversion:
Path.windows("foo", Path.posix("bar\\baz")).should eq Path.windows("foo").join(Path.posix("bar\\baz").to_windows)
end
end

Expand Down Expand Up @@ -592,6 +595,7 @@ describe Path do
it_joins_path("c:\\", "Program Files", "c:\\/Program Files", "c:\\Program Files")

it_joins_path("foo", Path.windows("bar\\baz"), "foo/bar/baz", "foo\\bar\\baz")
it_joins_path("foo", Path.posix("bar\\baz"), "foo/bar\\baz", "foo\\bar\uF05Cbaz")
it_joins_path("foo", Path.posix("bar/baz"), "foo/bar/baz", "foo\\bar/baz")
end

Expand Down
4 changes: 2 additions & 2 deletions src/path.cr
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,8 @@ struct Path
# Given that `File.join(arg1, arg2)` is the most common usage
# it's good if we can optimize this case.

if part.is_a?(Path) && posix? && part.windows?
part = part.to_posix.to_s
if part.is_a?(Path)
part = part.to_kind(@kind).to_s
else
part = part.to_s
part.check_no_null_byte
Expand Down

0 comments on commit 86927ef

Please sign in to comment.