]> cat aescling's git repositories - mastodon.git/blob - app/validators/html_validator.rb
Bump mini-css-extract-plugin from 1.3.8 to 1.3.9 (#15801)
[mastodon.git] / app / validators / html_validator.rb
1 # frozen_string_literal: true
2
3 class HtmlValidator < ActiveModel::EachValidator
4 ERROR_RE = /Opening and ending tag mismatch|Unexpected end tag/
5
6 def validate_each(record, attribute, value)
7 return if value.blank?
8
9 errors = html_errors(value)
10
11 record.errors.add(attribute, I18n.t('html_validator.invalid_markup', error: errors.first.to_s)) unless errors.empty?
12 end
13
14 private
15
16 def html_errors(str)
17 fragment = Nokogiri::HTML.fragment(options[:wrap_with] ? "<#{options[:wrap_with]}>#{str}</#{options[:wrap_with]}>" : str)
18 fragment.errors.select { |error| ERROR_RE.match?(error.message) }
19 end
20 end
This page took 0.069789 seconds and 4 git commands to generate.