module Loofah::HtmlDocumentBehavior::ClassMethods

Public Instance Methods

parse(*args, &block) click to toggle source
Calls superclass method
# File lib/loofah/concerns.rb, line 135
def parse(*args, &block)
  remove_comments_before_html_element(super)
end

Private Instance Methods

remove_comments_before_html_element(doc) click to toggle source

remove comments that exist outside of the HTML element.

these comments are allowed by the HTML spec:

https://www.w3.org/TR/html401/struct/global.html#h-7.1

but are not scrubbed by Loofah because these nodes don’t meet the contract that scrubbers expect of a node (e.g., it can be replaced, sibling and children nodes can be created).

# File lib/loofah/concerns.rb, line 150
def remove_comments_before_html_element(doc)
  doc.children.each do |child|
    child.unlink if child.comment?
  end
  doc
end