]>
cat aescling's git repositories - mastodon.git/blob - app/validators/html_validator.rb
1 # frozen_string_literal: true
3 class HtmlValidator
< ActiveModel
::EachValidator
4 ERROR_RE
= /Opening and ending tag mismatch|Unexpected end tag/
6 def validate_each(record
, attribute
, value
)
9 errors
= html_errors(value
)
11 record
.errors
.add(attribute
, I18n
.t('html_validator.invalid_markup', error
: errors
.first
.to_s
)) unless errors
.empty
?
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
) }
This page took 0.069789 seconds and 4 git commands to generate.