ActionView::Helpers::SanitizeHelper
def sanitize(html, options = {})

Description

Returns the HTML with disallowed tags and attributes removed.

Arguments

Changing a value updates the ERB and HTML.

Removes what is not in the allow list, as follows:
  • Tags: removed, keeping their content. Comments are removed too.
  • HTML attributes: removed. href attributes that start with javascript: or similar are removed too.
  • The style attribute: not in the allow list, so it is removed by default. When it is allowed with :attributes, removes disallowed CSS declarations from it, as sanitize_css does (if all of them are removed, style="" remains).
The allow list is the allowed_tags and allowed_attributes of Rails::HTML5::SafeListSanitizer (configurable with config.action_view.sanitized_allowed_tags and sanitized_allowed_attributes).
options= {}
%w[i]
Keeps only the given tags, replacing the allow list. Pass an array of strings (symbols do not match).
%w[style]
Keeps only the given HTML attributes, replacing the allow list. Pass an array of strings (symbols do not match).
Of the other options, only :scrubber is used: the given scrubber (a Loofah scrubber) decides what to remove, replacing the allow list. The rest are ignored.

ERB

Changes from the previous output: Added Removed Changed


          

HTML


          

Preview