0
0
Fork 0

Remove unused HTML Validator (#23866)

This commit is contained in:
Matt Jankowski 2023-02-24 14:06:32 -05:00 committed by GitHub
parent 8000a8f230
commit 730bb3e211
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
62 changed files with 0 additions and 141 deletions

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