require 'whitelist' module Sanitizer class << self def sanitize(text) new_text = text sanitize!(new_text) end def sanitize!(text) strip_tags(text) clean_spaces(text) clean_ampersand(text) text end def clean_spaces(text) text.gsub!(/\s+/, " ") text end def clean_ampersand(text) text.gsub!(/\&[^\w\;]+/, "& ") text end def strip_comments(text) text.gsub!(/(\<\!\-\-\b*[^\-\-\>]*.*?\-\-\>)/ui, "") text.gsub!(/(\<\s?\!--.*\s?--\>)/uim, "") text end # Remove all