Skip to content
This repository
Browse code

Only check that the option exists once instead of doing on each condi…

…tional
  • Loading branch information...
commit 9014a79436c8585ac17c8c27d14f7467cddd3562 1 parent 61fef76
Carlos Antonio da Silva carlosantoniodasilva authored

Showing 1 changed file with 9 additions and 8 deletions. Show diff stats Hide diff stats

  1. +9 8 activemodel/lib/active_model/validations/format.rb
17 activemodel/lib/active_model/validations/format.rb
@@ -38,14 +38,15 @@ def regexp_using_multiline_anchors?(regexp)
38 38 end
39 39
40 40 def check_options_validity(name)
41   - option = options[name]
42   - if option && !option.is_a?(Regexp) && !option.respond_to?(:call)
43   - raise ArgumentError, "A regular expression or a proc or lambda must be supplied as :#{name}"
44   - elsif option && option.is_a?(Regexp) &&
45   - regexp_using_multiline_anchors?(option) && options[:multiline] != true
46   - raise ArgumentError, "The provided regular expression is using multiline anchors (^ or $), " \
47   - "which may present a security risk. Did you mean to use \\A and \\z, or forgot to add the " \
48   - ":multiline => true option?"
  41 + if option = options[name]
  42 + if !option.is_a?(Regexp) && !option.respond_to?(:call)
  43 + raise ArgumentError, "A regular expression or a proc or lambda must be supplied as :#{name}"
  44 + elsif option.is_a?(Regexp) &&
  45 + regexp_using_multiline_anchors?(option) && options[:multiline] != true
  46 + raise ArgumentError, "The provided regular expression is using multiline anchors (^ or $), " \
  47 + "which may present a security risk. Did you mean to use \\A and \\z, or forgot to add the " \
  48 + ":multiline => true option?"
  49 + end
49 50 end
50 51 end
51 52 end

0 comments on commit 9014a79

Please sign in to comment.
Something went wrong with that request. Please try again.