Skip to content

Commit dd17800

Browse files
author
José Valim
committed
Do not expand ~ when not followed by a path separator
1 parent 064c8ce commit dd17800

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

lib/elixir/lib/path.ex

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -687,14 +687,9 @@ defmodule Path do
687687

688688
defp resolve_home(rest) do
689689
case {rest, major_os_type()} do
690-
{"\\" <> _, :win32} ->
691-
System.user_home!() <> rest
692-
693-
{"/" <> _, _} ->
694-
System.user_home!() <> rest
695-
696-
_ ->
697-
rest
690+
{"\\" <> _, :win32} -> System.user_home!() <> rest
691+
{"/" <> _, _} -> System.user_home!() <> rest
692+
_ -> "~" <> rest
698693
end
699694
end
700695

lib/elixir/test/elixir/path_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ defmodule PathTest do
135135

136136
assert Path.expand("~/file") == Path.join(home, "file")
137137
assert Path.expand("~/file", "whatever") == Path.join(home, "file")
138-
assert Path.expand("file", Path.expand("~")) == Path.expand("~/file")
138+
assert Path.expand("file", Path.expand("~")) == Path.join(home, "file")
139139
assert Path.expand("file", "~") == Path.join(home, "file")
140-
assert Path.expand("~file") == Path.join(File.cwd!(), "file")
140+
assert Path.expand("~file") == Path.join(File.cwd!(), "~file")
141141
end
142142

143143
test "expand/1,2" do

0 commit comments

Comments
 (0)