Skip to content

Commit 67f77ec

Browse files
whatyouhideJosé Valim
authored andcommitted
Fix Path.join/1 for lists of one element (#5639)
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 <[email protected]>
1 parent 8a91f64 commit 67f77ec

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/elixir/lib/path.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,10 @@ defmodule Path do
428428
end
429429

430430
@doc """
431-
Joins a list of strings.
431+
Joins a list of paths.
432432
433-
This function should be used to convert a list of strings to a path.
434-
Note that any trailing slash is removed on join.
433+
This function should be used to convert a list of paths to a path.
434+
Note that any trailing slash is removed when joining.
435435
436436
## Examples
437437
@@ -445,11 +445,11 @@ defmodule Path do
445445
"/foo/bar"
446446
447447
"""
448-
@spec join([t]) :: binary
448+
@spec join(nonempty_list(t)) :: binary
449449
def join([name1, name2 | rest]), do:
450450
join([join(name1, name2) | rest])
451451
def join([name]), do:
452-
name
452+
IO.chardata_to_string(name)
453453

454454
@doc """
455455
Joins two paths.

lib/elixir/test/elixir/path_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ defmodule PathTest do
211211
assert Path.join(['/foo/', "/bar/"]) == "/foo/bar"
212212
assert Path.join(["/", ""]) == "/"
213213
assert Path.join(["/", "", "bar"]) == "/bar"
214+
assert Path.join(['foo', [?b, "a", ?r]]) == "foo/bar"
215+
assert Path.join([[?f, 'o', "o"]]) == "foo"
214216
end
215217

216218
test "join two" do

0 commit comments

Comments
 (0)