Remove unused HTML Validator (#23866)

This commit is contained in:
Matt Jankowski authored and GitHub committed 2023-02-24 20:06:32 +01:00
1 parent 8000a8f230
commit 730bb3e211
62 files changed
-141

No files matched your search

-20
View File
@@ -1,20 +0,0 @@
# frozen_string_literal: true
class HtmlValidator < ActiveModel::EachValidator
ERROR_RE = /Opening and ending tag mismatch|Unexpected end tag/
def validate_each(record, attribute, value)
return if value.blank?
errors = html_errors(value)
record.errors.add(attribute, I18n.t('html_validator.invalid_markup', error: errors.first.to_s)) unless errors.empty?
end
private
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.match?(error.message) }
end
end