File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed
Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,13 @@ defmodule Regex do
6262 def compile ( source , options // "" )
6363
6464 def compile ( source , options ) when is_binary ( options ) do
65- compile ( source , translate_options ( options ) , options )
65+ case translate_options ( options ) do
66+ { :error , rest } ->
67+ { :error , { :invalid_option , rest } }
68+
69+ translated_options ->
70+ compile ( source , translated_options , options )
71+ end
6672 end
6773
6874 def compile ( source , options ) when is_list ( options ) do
@@ -357,6 +363,7 @@ defmodule Regex do
357363 defp translate_options ( << ?m , t :: binary >> ) , do: [ :multiline | translate_options ( t ) ]
358364 defp translate_options ( << ?g , t :: binary >> ) , do: [ :groups | translate_options ( t ) ]
359365 defp translate_options ( << >> ) , do: [ ]
366+ defp translate_options ( rest ) , do: { :error , rest }
360367
361368 { :ok , pattern } = :re . compile ( % B "\( \? <(?<G>[^>]*)>" )
362369 @groups_pattern pattern
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ defmodule Regex.BinaryTest do
2929 { :ok , regex } = Regex . compile ( "foo" )
3030 assert is_regex ( regex )
3131 assert { :error , _ } = Regex . compile ( "*foo" )
32+ assert { :error , _ } = Regex . compile ( "foo" , "y" )
3233 end
3334
3435 test :compile_with_erl_opts do
You can’t perform that action at this time.
0 commit comments