I am attempting to use the Sanitize method from ActionView.
The line r_str = Helper.instance.sanitize(r_str, :tags => @@allowed_tags, :attributes => @@allowed_attribs)
is giving me the error
undefined method `white_list_sanitizer' for Parsers::HTML::Helper:Class
This is my code in lib/parsers.rb
module Parsers
module HTML
@@allowed_tags = %w(--snip--)
@@allowed_attribs = %w(--snip--)
class Helper
include Singleton
include ActionView::Helpers::SanitizeHelper
end
#Use built-in santizer and the Hpricot plugin
def self.clean(str)
rgx = /<code>(.*?)<\/code>/ #All html within a code tag should be escaped.
r_str = str.gsub(rgx) { |match| "<code>" + CGI.escapeHTML(match[5..-7]) + "</code>" } # TODO: test this.
r_str = Helper.instance.sanitize(r_str, :tags => @@allowed_tags, :attributes => @@allowed_attribs)
Hpricot(r_str)
end
end
--snip--
end
What am I doing wrong?
(Please do not comment on the dangers of allowing user submitted HTML, I know the risks)