diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-11-15 01:01:59 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-11-15 01:01:59 -0200 |
commit | 9014a79436c8585ac17c8c27d14f7467cddd3562 (patch) | |
tree | 5dd8c197154d7c2b323fe77904f34f6ca730ea74 /activemodel/lib | |
parent | 61fef761065e310a8c398bd8f52da01cb82723e6 (diff) | |
download | rails-9014a79436c8585ac17c8c27d14f7467cddd3562.tar.gz rails-9014a79436c8585ac17c8c27d14f7467cddd3562.tar.bz2 rails-9014a79436c8585ac17c8c27d14f7467cddd3562.zip |
Only check that the option exists once instead of doing on each conditional
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/validations/format.rb | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/activemodel/lib/active_model/validations/format.rb b/activemodel/lib/active_model/validations/format.rb index f17105e574..488a498a41 100644 --- a/activemodel/lib/active_model/validations/format.rb +++ b/activemodel/lib/active_model/validations/format.rb @@ -38,14 +38,15 @@ module ActiveModel end def check_options_validity(name) - option = options[name] - if option && !option.is_a?(Regexp) && !option.respond_to?(:call) - raise ArgumentError, "A regular expression or a proc or lambda must be supplied as :#{name}" - elsif option && option.is_a?(Regexp) && - regexp_using_multiline_anchors?(option) && options[:multiline] != true - raise ArgumentError, "The provided regular expression is using multiline anchors (^ or $), " \ - "which may present a security risk. Did you mean to use \\A and \\z, or forgot to add the " \ - ":multiline => true option?" + if option = options[name] + if !option.is_a?(Regexp) && !option.respond_to?(:call) + raise ArgumentError, "A regular expression or a proc or lambda must be supplied as :#{name}" + elsif option.is_a?(Regexp) && + regexp_using_multiline_anchors?(option) && options[:multiline] != true + raise ArgumentError, "The provided regular expression is using multiline anchors (^ or $), " \ + "which may present a security risk. Did you mean to use \\A and \\z, or forgot to add the " \ + ":multiline => true option?" + end end end end |