Created
April 18, 2020 06:54
-
-
Save amolpujari/943624b9268043fd76772f0954d432de to your computer and use it in GitHub Desktop.
Sanitizer Helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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