Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/elixir/src/elixir_import.erl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ is_sigil({Name, 2}) ->
[H|T] when H >= $A, H =< $Z ->
lists:all(fun(L) -> (L >= $0 andalso L =< $9)
orelse (L>= $A andalso L =< $Z)
end, T)
end, T);
_ -> false
end;
_ ->
false
Expand Down
14 changes: 14 additions & 0 deletions lib/elixir/test/elixir/kernel/import_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ defmodule Kernel.ImportTest do
defmacro bor(x, _), do: x
end

defmodule ModuleWithInvalidSigils do
def sigil_ab(string, []), do: string
def sigil_1(string, []), do: string
def helper(x), do: x
end

test "import only sigils" do
import Kernel, except: [sigil_w: 2]
import ModuleWithSigils, only: :sigils
Expand All @@ -204,6 +210,14 @@ defmodule Kernel.ImportTest do
assert ~w(abc def) == ["abc", "def"]
end

test "import only sigils ignores malformed sigil names" do
import ModuleWithInvalidSigils, only: :sigils

assert Macro.Env.lookup_import(__ENV__, {:sigil_ab, 2}) == []
assert Macro.Env.lookup_import(__ENV__, {:sigil_1, 2}) == []
assert Macro.Env.lookup_import(__ENV__, {:helper, 1}) == []
end

test "import only removes the non-import part" do
import List
import List, only: :macros
Expand Down
Loading