Class: Loofah::Scrubbers::Prune

Inherits:
Loofah::Scrubber show all
Defined in:
lib/loofah/scrubbers.rb

Overview

scrub!(:prune)

+:prune+ removes unknown/unsafe tags and their contents (including their subtrees):

   unsafe_html = "ohai! <div>div is safe</div> <foo>but foo is <b>not</b></foo>"
   Loofah.html5_fragment(unsafe_html).scrub!(:prune)
   => "ohai! <div>div is safe</div> "

Constant Summary

Constants inherited from Loofah::Scrubber

Loofah::Scrubber::CONTINUE, Loofah::Scrubber::STOP

Instance Attribute Summary

Attributes inherited from Loofah::Scrubber

#block, #direction

Instance Method Summary collapse

Methods inherited from Loofah::Scrubber

#append_attribute, #traverse

Constructor Details

#initializePrune

rubocop:disable Lint/MissingSuper



121
122
123
# File 'lib/loofah/scrubbers.rb', line 121

def initialize # rubocop:disable Lint/MissingSuper
  @direction = :top_down
end

Instance Method Details

#scrub(node) ⇒ Object



125
126
127
128
129
130
# File 'lib/loofah/scrubbers.rb', line 125

def scrub(node)
  return CONTINUE if html5lib_sanitize(node) == CONTINUE

  node.remove
  STOP
end