Skip to content

Commit

Permalink
Fix Path.join/1 for lists of one element (#5639)
Browse files Browse the repository at this point in the history
Also fix the spec for Path.join/1 to mention that the input list of paths has to
be non-empty, and fix the documentation to mention that this function takes a
list of paths (Path.t), not strings like it said before.

Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
  • Loading branch information
whatyouhide authored and José Valim committed Jan 10, 2017
1 parent 8a91f64 commit 67f77ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/elixir/lib/path.ex
Expand Up @@ -428,10 +428,10 @@ defmodule Path do
end

@doc """
Joins a list of strings.
Joins a list of paths.
This function should be used to convert a list of strings to a path.
Note that any trailing slash is removed on join.
This function should be used to convert a list of paths to a path.
Note that any trailing slash is removed when joining.
## Examples
Expand All @@ -445,11 +445,11 @@ defmodule Path do
"/foo/bar"
"""
@spec join([t]) :: binary
@spec join(nonempty_list(t)) :: binary
def join([name1, name2 | rest]), do:
join([join(name1, name2) | rest])
def join([name]), do:
name
IO.chardata_to_string(name)

@doc """
Joins two paths.
Expand Down
2 changes: 2 additions & 0 deletions lib/elixir/test/elixir/path_test.exs
Expand Up @@ -211,6 +211,8 @@ defmodule PathTest do
assert Path.join(['/foo/', "/bar/"]) == "/foo/bar"
assert Path.join(["/", ""]) == "/"
assert Path.join(["/", "", "bar"]) == "/bar"
assert Path.join(['foo', [?b, "a", ?r]]) == "foo/bar"
assert Path.join([[?f, 'o', "o"]]) == "foo"
end

test "join two" do
Expand Down

0 comments on commit 67f77ec

Please sign in to comment.