]> cat aescling's git repositories - mastodon.git/blob - app/validators/html_validator.rb
Add validations to admin settings (#10348)
[mastodon.git] / app / validators / html_validator.rb
1 # frozen_string_literal: true
2
3 class HtmlValidator < ActiveModel::EachValidator
4 def validate_each(record, attribute, value)
5 return if value.blank?
6 record.errors.add(attribute, I18n.t('html_validator.invalid_markup')) unless valid_html?(value)
7 end
8
9 private
10
11 def valid_html?(str)
12 Nokogiri::HTML.fragment(str).to_s == str
13 end
14 end
This page took 0.080588 seconds and 5 git commands to generate.