Class: Sanitize::Transformers::CSS::CleanAttribute
- Inherits:
-
Object
- Object
- Sanitize::Transformers::CSS::CleanAttribute
- Defined in:
- lib/sanitize/transformers/clean_css.rb
Overview
Enforces a CSS allowlist on the contents of ‘style` attributes.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(sanitizer_or_config) ⇒ CleanAttribute
constructor
A new instance of CleanAttribute.
Constructor Details
#initialize(sanitizer_or_config) ⇒ CleanAttribute
Returns a new instance of CleanAttribute.
8 9 10 11 12 13 14 |
# File 'lib/sanitize/transformers/clean_css.rb', line 8 def initialize(sanitizer_or_config) @scss = if Sanitize::CSS === sanitizer_or_config sanitizer_or_config else Sanitize::CSS.new(sanitizer_or_config) end end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sanitize/transformers/clean_css.rb', line 16 def call(env) node = env[:node] return unless node.type == Nokogiri::XML::Node::ELEMENT_NODE && node.key?("style") && !env[:is_allowlisted] attr = node.attribute("style") css = @scss.properties(attr.value) if css.strip.empty? attr.unlink else attr.value = css end end |