module Rails::HTML::Concern::Scrubber::SafeList
def self.included(klass)
def self.included(klass) class << klass attr_accessor :allowed_tags attr_accessor :allowed_attributes end klass.allowed_tags = DEFAULT_ALLOWED_TAGS.dup klass.allowed_attributes = DEFAULT_ALLOWED_ATTRIBUTES.dup end
def allowed_attributes(options)
def allowed_attributes(options) options[:attributes] || self.class.allowed_attributes end
def allowed_tags(options)
def allowed_tags(options) options[:tags] || self.class.allowed_tags end
def initialize(prune: false)
def initialize(prune: false) @permit_scrubber = PermitScrubber.new(prune: prune) end
def sanitize_css(style_string)
def sanitize_css(style_string) Loofah::HTML5::Scrub.scrub_css(style_string) end
def scrub(fragment, options = {})
def scrub(fragment, options = {}) if scrubber = options[:scrubber] # No duck typing, Loofah ensures subclass of Loofah::Scrubber fragment.scrub!(scrubber) elsif allowed_tags(options) || allowed_attributes(options) @permit_scrubber.tags = allowed_tags(options) @permit_scrubber.attributes = allowed_attributes(options) fragment.scrub!(@permit_scrubber) else fragment.scrub!(:strip) end end