diff options
author | luigi <007.lva@gmail.com> | 2021-01-22 04:09:08 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-22 10:09:08 +0100 |
commit | eb51e43fb4386120f77f2ff99581f15018a81bd4 (patch) | |
tree | ac52a3d084a3eafc1a1943be8ab2393465abc1ec /app/validators | |
parent | 7d0031a515a9ccd552fab9ad55b6edb7e0e5ba32 (diff) |
Optimize some regex matching (#15528)
* Use Regex#match? * Replace =~ too * Avoid to call match? from Nil * Keep value of Regexp.last_match
Diffstat (limited to 'app/validators')
-rw-r--r-- | app/validators/blacklisted_email_validator.rb | 2 | ||||
-rw-r--r-- | app/validators/html_validator.rb | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/app/validators/blacklisted_email_validator.rb b/app/validators/blacklisted_email_validator.rb index 16e3abf12..20a1587cc 100644 --- a/app/validators/blacklisted_email_validator.rb +++ b/app/validators/blacklisted_email_validator.rb @@ -22,7 +22,7 @@ class BlacklistedEmailValidator < ActiveModel::Validator domains = Rails.configuration.x.email_domains_blacklist.gsub('.', '\.') regexp = Regexp.new("@(.+\\.)?(#{domains})", true) - @email =~ regexp + regexp.match?(@email) end def not_on_whitelist? diff --git a/app/validators/html_validator.rb b/app/validators/html_validator.rb index 1c9cd303c..b85b9769f 100644 --- a/app/validators/html_validator.rb +++ b/app/validators/html_validator.rb @@ -15,6 +15,6 @@ class HtmlValidator < ActiveModel::EachValidator def html_errors(str) fragment = Nokogiri::HTML.fragment(options[:wrap_with] ? "<#{options[:wrap_with]}>#{str}</#{options[:wrap_with]}>" : str) - fragment.errors.select { |error| ERROR_RE =~ error.message } + fragment.errors.select { |error| ERROR_RE.match?(error.message) } end end |