Skip to content

Commit d1773cf

Browse files
Daniel PerezJosé Valim
authored andcommitted
Fix bug in Path.join. Fix #4252.
Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
1 parent 5754da2 commit d1773cf

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/elixir/lib/path.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,11 @@ defmodule Path do
470470
end
471471

472472
defp do_join("", right, os_type), do: relative(right, os_type)
473-
defp do_join(left, "", _os_type), do: left
473+
defp do_join("/", right, os_type), do: "/" <> relative(right, os_type)
474474
defp do_join(left, right, os_type), do: remove_dirsep(left, os_type) <> "/" <> relative(right, os_type)
475475

476476
defp remove_dirsep("", _os_type), do: ""
477+
defp remove_dirsep("/", _os_type), do: "/"
477478
defp remove_dirsep(bin, os_type) do
478479
last = :binary.last(bin)
479480
if last == ?/ or (last == ?\\ and os_type == :win32) do

lib/elixir/test/elixir/path_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ defmodule PathTest do
207207
assert Path.join(["/", "foo", "bar"]) == "/foo/bar"
208208
assert Path.join(["~", "foo", "bar"]) == "~/foo/bar"
209209
assert Path.join(['/foo/', "/bar/"]) == "/foo/bar"
210+
assert Path.join(["/", ""]) == "/"
211+
assert Path.join(["/", "", "bar"]) == "/bar"
210212
end
211213

212214
test "join two" do

0 commit comments

Comments
 (0)