Skip to content

Commit 7098ac8

Browse files
committed
Preserve . semantics in Path.relative_to, closes #13310
1 parent e0658bb commit 7098ac8

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

lib/elixir/lib/path.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ defmodule Path do
424424
defp relative_to_unforced(_, _, original), do: join(original)
425425

426426
defp relative_to_forced(path, path, _original), do: "."
427+
defp relative_to_forced(["."], _path, _original), do: "."
428+
defp relative_to_forced(path, ["."], _original), do: join(path)
427429
defp relative_to_forced([h | t1], [h | t2], original), do: relative_to_forced(t1, t2, original)
428430

429431
# this should only happen if we have two paths on different drives on windows

lib/elixir/test/elixir/path_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ defmodule PathTest do
316316
assert Path.relative_to("./foo/../bar/..", File.cwd!()) == "."
317317

318318
# both relative
319+
assert Path.relative_to("usr/local/foo", ".") == "usr/local/foo"
320+
assert Path.relative_to(".", "usr/local/foo") == "."
319321
assert Path.relative_to("usr/local/foo", "usr/local") == "foo"
320322
assert Path.relative_to("usr/local/foo", "etc") == "../usr/local/foo"
321323
assert Path.relative_to(~c"usr/local/foo", "etc") == "../usr/local/foo"

0 commit comments

Comments
 (0)