Reputation: 143
I am using the sanitize gem https://github.com/rgrove/sanitize to remove some HTML tags from a string.
However, before sanitizing the string in my controller, the string is being set as follows:
<p>This is <b>bold</b> and this <span style="text-decoration: underline;">is</span> <i>italics</i> ok? This <em>is not </em>a problem.</p>
meaning that < and > are being replaced by <
and >
.
How can I use the sanitize gem to remove for example and when these tags are being represented as <i>
and </i>
in the controller?
Upvotes: 0
Views: 3275
Reputation: 10493
If you want the escaped HTML tags (< and >) to be treated as HTML for the purposes of sanitizing, then you'll have to unescape them first:
require 'cgi' Sanitize.clean(CGI.unescapeHTML(your_string))
Upvotes: 6