diff --git a/lib/elixir/src/elixir_import.erl b/lib/elixir/src/elixir_import.erl index ea7e07833cc..ffbbc85cb5b 100644 --- a/lib/elixir/src/elixir_import.erl +++ b/lib/elixir/src/elixir_import.erl @@ -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 diff --git a/lib/elixir/test/elixir/kernel/import_test.exs b/lib/elixir/test/elixir/kernel/import_test.exs index 900d069f193..d599ea5552e 100644 --- a/lib/elixir/test/elixir/kernel/import_test.exs +++ b/lib/elixir/test/elixir/kernel/import_test.exs @@ -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 @@ -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