提交 68f75b97 编写于 作者: T Timm

Extracted the xpath removals into some new API that allows users to remove xpath subtrees.

上级 55b453f2
......@@ -49,8 +49,7 @@ def sanitize(html, options = {})
@permit_scrubber.attributes = options[:attributes]
loofah_fragment.scrub!(@permit_scrubber)
else
loofah_fragment.xpath("./script").each { |script| script.remove }
loofah_fragment.xpath("./form").each { |form| form.remove }
remove_xpaths(loofah_fragment, %w(./script ./form))
loofah_fragment.scrub!(:strip)
end
loofah_fragment.to_s
......@@ -60,6 +59,13 @@ def sanitize_css(style_string)
Loofah::HTML5::Scrub.scrub_css style_string
end
def remove_xpaths(html, *xpaths)
html = Loofah.fragment(html) unless html.is_a? Nokogiri::XML::DocumentFragment
xpaths.each do |xpath|
html.xpath(xpath).each { |subtree| subtree.remove }
end
end
def protocol_separator
self.class.protocol_separator
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册