File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -62,10 +62,13 @@ defmodule Path do
62
62
case type ( path ) do
63
63
:relative -> join ( relative_to , path )
64
64
:absolute ->
65
- if :binary . last ( path ) == ?/ do
66
- binary_part ( path , 0 , byte_size ( path ) - 1 )
67
- else
68
- path
65
+ cond do
66
+ :binary . first ( path ) == ?/ and size ( path ) == 1 ->
67
+ path
68
+ :binary . last ( path ) == ?/ ->
69
+ binary_part ( path , 0 , byte_size ( path ) - 1 )
70
+ true ->
71
+ path
69
72
end
70
73
:volumerelative ->
71
74
relative_to = IO . chardata_to_string ( relative_to )
@@ -138,6 +141,7 @@ defmodule Path do
138
141
139
142
## Unix examples
140
143
144
+ Path.type("/") #=> :absolute
141
145
Path.type("/usr/local/bin") #=> :absolute
142
146
Path.type("usr/local/bin") #=> :relative
143
147
Path.type("../usr/local/bin") #=> :relative
Original file line number Diff line number Diff line change @@ -65,6 +65,8 @@ defmodule PathTest do
65
65
end
66
66
67
67
test :absname do
68
+ assert ( Path . absname ( "/" ) |> strip_drive_letter_if_windows ) == "/"
69
+ assert ( Path . absname ( "/foo" ) |> strip_drive_letter_if_windows ) == "/foo"
68
70
assert ( Path . absname ( "/foo/bar" ) |> strip_drive_letter_if_windows ) == "/foo/bar"
69
71
assert ( Path . absname ( "/foo/bar/" ) |> strip_drive_letter_if_windows ) == "/foo/bar"
70
72
assert ( Path . absname ( "/foo/bar/../bar" ) |> strip_drive_letter_if_windows ) == "/foo/bar/../bar"
@@ -92,6 +94,8 @@ defmodule PathTest do
92
94
end
93
95
94
96
test :expand_path do
97
+ assert ( Path . expand ( "/" ) |> strip_drive_letter_if_windows ) == "/"
98
+ assert ( Path . expand ( "/foo" ) |> strip_drive_letter_if_windows ) == "/foo"
95
99
assert ( Path . expand ( "/foo/bar" ) |> strip_drive_letter_if_windows ) == "/foo/bar"
96
100
assert ( Path . expand ( "/foo/bar/" ) |> strip_drive_letter_if_windows ) == "/foo/bar"
97
101
assert ( Path . expand ( "/foo/bar/." ) |> strip_drive_letter_if_windows ) == "/foo/bar"
You can’t perform that action at this time.
0 commit comments