From 86927efe396276e5084d90d73de0e76ccc02ba83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Mon, 23 May 2022 08:55:09 +0200 Subject: [PATCH] Fix `Path#join` to convert argument path to base kind (#12033) --- spec/std/path_spec.cr | 4 ++++ src/path.cr | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/std/path_spec.cr b/spec/std/path_spec.cr index 219181f32aeb..784884312da4 100644 --- a/spec/std/path_spec.cr +++ b/spec/std/path_spec.cr @@ -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 @@ -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 diff --git a/src/path.cr b/src/path.cr index ddb03a81ef80..f7509acf171b 100644 --- a/src/path.cr +++ b/src/path.cr @@ -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