diff --git a/lib/elixir/lib/path.ex b/lib/elixir/lib/path.ex index 090899aa726..f2fbd02b87b 100644 --- a/lib/elixir/lib/path.ex +++ b/lib/elixir/lib/path.ex @@ -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]) @@ -110,6 +112,11 @@ defmodule Path do do_absname_join(rest, relativename, [?:, uc_letter + ?a - ?A], :win32) end + defp do_absname_join(<>, relativename, [], :win32) + when c1 in @slash and c2 in @slash do + do_absname_join(rest, relativename, '//', :win32) + end + defp do_absname_join(<>, relativename, result, :win32), do: do_absname_join(<>, relativename, result, :win32) @@ -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), diff --git a/lib/elixir/test/elixir/path_test.exs b/lib/elixir/test/elixir/path_test.exs index 4ad0c99367e..6d1daafa156 100644 --- a/lib/elixir/test/elixir/path_test.exs +++ b/lib/elixir/test/elixir/path_test.exs @@ -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" @@ -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