Skip to content

Instantly share code, notes, and snippets.

@amolpujari
Created April 18, 2020 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amolpujari/943624b9268043fd76772f0954d432de to your computer and use it in GitHub Desktop.
Save amolpujari/943624b9268043fd76772f0954d432de to your computer and use it in GitHub Desktop.
Sanitizer Helper
module SanitizerHelper
def sanitize text
text = text.to_s.
gsub("?xml","").
gsub(/DOCTYPE|json|CDATA/,"").
gsub("<p><br></p>", "<br/>").
gsub(/\<(script|iframe|xml|applet|body|code|em|form|html|head|header|footer|input|textarea|map|nav|pre|template|tab|var|video|canvas|audio|ruby|wbrxlink|xs|binding|soap|rdf|channel|rss)/,"").
gsub(/ +/," ").
gsub(/(\<br\>)+/,"<br>").
gsub(/\n+/,"\n").
strip
return if text.blank?
text
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment