Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/elixir/lib/path.ex
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ defmodule Path do
absname(absname_join(name), cwd)
end

@slash [?/, ?\\]

# Joins a list
defp absname_join([name1, name2 | rest]), do: absname_join([absname_join(name1, name2) | rest])

Expand All @@ -110,6 +112,11 @@ defmodule Path do
do_absname_join(rest, relativename, [?:, uc_letter + ?a - ?A], :win32)
end

defp do_absname_join(<<c1, c2, rest::binary>>, relativename, [], :win32)
when c1 in @slash and c2 in @slash do
do_absname_join(rest, relativename, '//', :win32)
end

defp do_absname_join(<<?\\, rest::binary>>, relativename, result, :win32),
do: do_absname_join(<<?/, rest::binary>>, relativename, result, :win32)

Expand Down Expand Up @@ -254,8 +261,6 @@ defmodule Path do
defp unix_pathtype([list | rest]) when is_list(list), do: unix_pathtype(list ++ rest)
defp unix_pathtype(relative), do: {:relative, relative}

@slash [?/, ?\\]

defp win32_pathtype([list | rest]) when is_list(list), do: win32_pathtype(list ++ rest)

defp win32_pathtype([char, list | rest]) when is_list(list),
Expand Down
12 changes: 12 additions & 0 deletions lib/elixir/test/elixir/path_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ defmodule PathTest do
describe "Windows" do
@describetag :windows

test "absname/1" do
assert Path.absname("//host/path") == "//host/path"
assert Path.absname("\\\\host\\path") == "//host/path"
assert Path.absname("\\/host\\path") == "//host/path"
assert Path.absname("/\\host\\path") == "//host/path"
end

test "relative/1" do
assert Path.relative("C:/usr/local/bin") == "usr/local/bin"
assert Path.relative("C:\\usr\\local\\bin") == "usr\\local\\bin"
Expand Down Expand Up @@ -67,6 +74,11 @@ defmodule PathTest do
assert Path.type("/usr/local/bin") == :volumerelative
assert Path.type('usr/local/bin') == :relative
assert Path.type("../usr/local/bin") == :relative

assert Path.type("//host/path") == :absolute
assert Path.type("\\\\host\\path") == :absolute
assert Path.type("/\\host\\path") == :absolute
assert Path.type("\\/host\\path") == :absolute
end

test "split/1" do
Expand Down