Skip to content

Commit 177a900

Browse files
committed
Make Mix.Utils.Underscore accept .'s and empty args
1 parent c881344 commit 177a900

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/mix/lib/mix/utils.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ defmodule Mix.Utils do
194194
underscore(rest)
195195
end
196196

197+
def underscore(""), do: ""
198+
197199
def underscore(<<h, t :: binary>>) do
198200
<<to_lower_char(h)>> <> do_underscore(t, h)
199201
end
@@ -210,6 +212,12 @@ defmodule Mix.Utils do
210212
<<?_>> <> do_underscore(t, ?-)
211213
end
212214

215+
defp do_underscore(<< "..", t :: binary>>, _) do
216+
<<"..">> <> underscore(t)
217+
end
218+
219+
defp do_underscore(<<?.>>, _), do: <<?.>>
220+
213221
defp do_underscore(<<?., t :: binary>>, _) do
214222
<<?/>> <> underscore(t)
215223
end

lib/mix/test/mix/utils_test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ defmodule Mix.UtilsTest do
5252
assert Mix.Utils.underscore("FoBaZa") == "fo_ba_za"
5353
assert Mix.Utils.underscore("Foo.Bar") == "foo/bar"
5454
assert Mix.Utils.underscore(Foo.Bar) == "foo/bar"
55+
assert Mix.Utils.underscore("") == ""
56+
assert Mix.Utils.underscore("..") == ".."
57+
assert Mix.Utils.underscore("/..") == "/.."
58+
assert Mix.Utils.underscore("foo/../bar") == "foo/../bar"
5559
end
5660

5761
test :camelize do

0 commit comments

Comments
 (0)