From eb51e43fb4386120f77f2ff99581f15018a81bd4 Mon Sep 17 00:00:00 2001 From: luigi <007.lva@gmail.com> Date: Fri, 22 Jan 2021 04:09:08 -0500 Subject: Optimize some regex matching (#15528) * Use Regex#match? * Replace =~ too * Avoid to call match? from Nil * Keep value of Regexp.last_match --- app/validators/html_validator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/validators/html_validator.rb') 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}" : str) - fragment.errors.select { |error| ERROR_RE =~ error.message } + fragment.errors.select { |error| ERROR_RE.match?(error.message) } end end -- cgit