Permalink
Browse files

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

…tional
  • Loading branch information...
1 parent 61fef76 commit 9014a79436c8585ac17c8c27d14f7467cddd3562 @carlosantoniodasilva carlosantoniodasilva committed Nov 15, 2013
Showing with 9 additions and 8 deletions.
  1. +9 −8 activemodel/lib/active_model/validations/format.rb
@@ -38,14 +38,15 @@ def regexp_using_multiline_anchors?(regexp)
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

0 comments on commit 9014a79

Please sign in to comment.