Skip to content

Commit a2f14bd

Browse files
author
José Valim
committed
Consider options when running regexes on the fly
Closes #9343.
1 parent 66ac6a3 commit a2f14bd

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/elixir/lib/regex.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,13 +461,13 @@ defmodule Regex do
461461
end
462462

463463
defp safe_run(
464-
%Regex{re_pattern: compiled, source: source, re_version: version},
464+
%Regex{re_pattern: compiled, source: source, re_version: version, opts: compile_opts},
465465
string,
466466
options
467467
) do
468468
case version() do
469469
^version -> :re.run(string, compiled, options)
470-
_ -> :re.run(string, source, options)
470+
_ -> :re.run(string, source, translate_options(compile_opts, options))
471471
end
472472
end
473473

lib/elixir/test/elixir/regex_test.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ defmodule RegexTest do
194194
assert Regex.run(@re_19_3_little, "abcd abce", capture: :all_names) == ["d"]
195195
end
196196

197+
test "run/3 with regexes with options compiled in different systems" do
198+
assert Regex.run(%{~r/foo/i | re_version: "bad version"}, "FOO") == ["FOO"]
199+
end
200+
197201
test "scan/2" do
198202
assert Regex.scan(~r"c(d|e)", "abcd abce") == [["cd", "d"], ["ce", "e"]]
199203
assert Regex.scan(~r"c(?:d|e)", "abcd abce") == [["cd"], ["ce"]]
@@ -213,6 +217,10 @@ defmodule RegexTest do
213217
assert Regex.scan(@re_19_3_little, "abcd abce", capture: :all_names) == [["d"], ["e"]]
214218
end
215219

220+
test "scan/2 with regexes with options compiled in different systems" do
221+
assert Regex.scan(%{~r/foo/i | re_version: "bad version"}, "FOO") == [["FOO"]]
222+
end
223+
216224
test "split/2,3" do
217225
assert Regex.split(~r",", "") == [""]
218226
assert Regex.split(~r",", "", trim: true) == []

0 commit comments

Comments
 (0)