闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
349 B

  1. # frozen_string_literal: true
  2. class HtmlValidator < ActiveModel::EachValidator
  3. def validate_each(record, attribute, value)
  4. return if value.blank?
  5. record.errors.add(attribute, I18n.t('html_validator.invalid_markup')) unless valid_html?(value)
  6. end
  7. private
  8. def valid_html?(str)
  9. Nokogiri::HTML.fragment(str).to_s == str
  10. end
  11. end