Skip to content

Commit a3d1ee6

Browse files
author
José Valim
committed
Use the new Path.relative_to and ensure it won't fail for equals paths
1 parent 204abb6 commit a3d1ee6

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

lib/elixir/lib/exception.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ defmodule Exception do
176176
file = to_binary(file)
177177

178178
if cwd do
179-
file = :binary.replace(file, cwd <> "/", "")
179+
file = Path.relative_to(file, cwd)
180180
end
181181

182182
if line && line != 0 do

lib/elixir/lib/path.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ defmodule Path do
120120
relative_to(t1, t2, original)
121121
end
122122

123-
defp relative_to(t1, [], _original) do
124-
FN.join(t1)
123+
defp relative_to([_|_] = l1, [], _original) do
124+
FN.join(l1)
125125
end
126126

127127
defp relative_to(_, _, original) do

lib/elixir/test/elixir/path_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ defmodule PathTest do
5757
assert Path.relative_to("/usr/local/foo", "/usr/local") == "foo"
5858
assert Path.relative_to("/usr/local/foo", "/") == "usr/local/foo"
5959
assert Path.relative_to("/usr/local/foo", "/etc") == "/usr/local/foo"
60+
assert Path.relative_to("/usr/local/foo", "/usr/local/foo") == "/usr/local/foo"
6061

6162
assert Path.relative_to("usr/local/foo", "usr/local") == "foo"
6263
assert Path.relative_to("usr/local/foo", "etc") == "usr/local/foo"

0 commit comments

Comments
 (0)