1
0
Fork 0
forked from gitea/nas

Optimize some regex matching (#15528)

* Use Regex#match?

* Replace =~ too

* Avoid to call match? from Nil

* Keep value of Regexp.last_match
This commit is contained in:
luigi 2021-01-22 04:09:08 -05:00 committed by GitHub
parent 7d0031a515
commit eb51e43fb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 20 additions and 20 deletions

View file

@ -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?

View file

@ -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