diff options
author | José Valim <jose.valim@plataformatec.com.br> | 2019-10-11 17:43:45 +0200 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2019-10-11 17:44:23 +0200 |
commit | c0ae3645f752fdea5ecce59398612fb555cffbd2 (patch) | |
tree | da3177f7c2f4e0e643c45ffcb50cfcc5f337aa43 | |
parent | 0eb3fbbf41eb0e9aede944b6dd7afa4a55b87f80 (diff) | |
download | elixir-c0ae3645f752fdea5ecce59398612fb555cffbd2.tar.gz |
Consider options when running regexes on the fly
Closes #9343.
-rw-r--r-- | lib/elixir/lib/regex.ex | 4 | ||||
-rw-r--r-- | lib/elixir/test/elixir/regex_test.exs | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/elixir/lib/regex.ex b/lib/elixir/lib/regex.ex index 331f76675..c61223b4b 100644 --- a/lib/elixir/lib/regex.ex +++ b/lib/elixir/lib/regex.ex @@ -462,13 +462,13 @@ defmodule Regex do end defp safe_run( - %Regex{re_pattern: compiled, source: source, re_version: version}, + %Regex{re_pattern: compiled, source: source, re_version: version, opts: compile_opts}, string, options ) do case version() do ^version -> :re.run(string, compiled, options) - _ -> :re.run(string, source, options) + _ -> :re.run(string, source, translate_options(compile_opts, options)) end end diff --git a/lib/elixir/test/elixir/regex_test.exs b/lib/elixir/test/elixir/regex_test.exs index 37f96fed2..2aeef63f6 100644 --- a/lib/elixir/test/elixir/regex_test.exs +++ b/lib/elixir/test/elixir/regex_test.exs @@ -194,6 +194,10 @@ defmodule RegexTest do assert Regex.run(@re_19_3_little, "abcd abce", capture: :all_names) == ["d"] end + test "run/3 with regexes with options compiled in different systems" do + assert Regex.run(%{~r/foo/i | re_version: "bad version"}, "FOO") == ["FOO"] + end + test "scan/2" do assert Regex.scan(~r"c(d|e)", "abcd abce") == [["cd", "d"], ["ce", "e"]] assert Regex.scan(~r"c(?:d|e)", "abcd abce") == [["cd"], ["ce"]] @@ -213,6 +217,10 @@ defmodule RegexTest do assert Regex.scan(@re_19_3_little, "abcd abce", capture: :all_names) == [["d"], ["e"]] end + test "scan/2 with regexes with options compiled in different systems" do + assert Regex.scan(%{~r/foo/i | re_version: "bad version"}, "FOO") == [["FOO"]] + end + test "split/2,3" do assert Regex.split(~r",", "") == [""] assert Regex.split(~r",", "", trim: true) == [] |