提交 5430487d 编写于 作者: T Timm

Stylistic improvements. Some light documentation for remove_xpaths.

上级 170f4149
......@@ -5,12 +5,13 @@
module ActionView
XPATHS_TO_REMOVE = %w{.//script .//form comment()}
class Sanitizer
# :nodoc:
class Sanitizer # :nodoc:
def sanitize(html, options = {})
raise NotImplementedError, "subclasses must implement"
end
# call +remove_xpaths+ with string and get a string back
# call it with a node or nodeset and get back a node/nodeset
def remove_xpaths(html, xpaths)
if html.respond_to?(:xpath)
html.xpath(*xpaths).remove
......@@ -23,7 +24,7 @@ def remove_xpaths(html, xpaths)
class FullSanitizer < Sanitizer
def sanitize(html, options = {})
return nil unless html
return unless html
return html if html.empty?
Loofah.fragment(html).tap do |fragment|
......@@ -44,15 +45,15 @@ def sanitize(html, options = {})
end
class WhiteListSanitizer < Sanitizer
def initialize
@permit_scrubber = PermitScrubber.new
end
def sanitize(html, options = {})
return nil unless html
return unless html
loofah_fragment = Loofah.fragment(html)
if scrubber = options[:scrubber]
# No duck typing, Loofah ensures subclass of Loofah::Scrubber
loofah_fragment.scrub!(scrubber)
......@@ -64,11 +65,12 @@ def sanitize(html, options = {})
remove_xpaths(loofah_fragment, XPATHS_TO_REMOVE)
loofah_fragment.scrub!(:strip)
end
loofah_fragment.to_s
end
def sanitize_css(style_string)
Loofah::HTML5::Scrub.scrub_css style_string
Loofah::HTML5::Scrub.scrub_css(style_string)
end
def protocol_separator
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册