Class: Shamu::Attributes::HtmlSanitation::PermitScrubber

Inherits:
Loofah::Scrubber
  • Object
show all
Defined in:
lib/shamu/attributes/html_sanitation.rb

Direct Known Subclasses

BodyScrubber, SafeScrubber, SimpleScrubber

Instance Method Summary collapse

Constructor Details

#initializePermitScrubber

Returns a new instance of PermitScrubber.



173
174
175
# File 'lib/shamu/attributes/html_sanitation.rb', line 173

def initialize
  @direction = :bottom_up
end

Instance Method Details

#allowed_element?(name) ⇒ Boolean

Returns:

  • (Boolean)


190
191
# File 'lib/shamu/attributes/html_sanitation.rb', line 190

def allowed_element?( name )
end

#scrub(node) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/shamu/attributes/html_sanitation.rb', line 177

def scrub( node )
  if node.type == Nokogiri::XML::Node::ELEMENT_NODE
    if allowed_element?( node.name )
      Loofah::HTML5::Scrub.scrub_attributes node
    else
      node.before node.children unless unsafe_element?( node.name )
      node.remove
    end
  end

  Loofah::Scrubber::CONTINUE
end

#unsafe_element?(name) ⇒ Boolean

Returns:

  • (Boolean)


193
194
195
# File 'lib/shamu/attributes/html_sanitation.rb', line 193

def unsafe_element?( name )
  UNSAFE_TAGS.include?( name.upcase )
end