0
votes

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 &lt;b&gt;bold&lt;/b&gt; and this <span style="text-decoration: underline;">is</span> &lt;i&gt;italics&lt;/i&gt; ok? This <em>is not </em>a problem.</p>

meaning that < and > are being replaced by &lt; and &gt;.

How can I use the sanitize gem to remove for example and when these tags are being represented as &lt;i&gt; and &lt;/i&gt; in the controller?

1
I'm not sure I understand your english. What is the undesired outcome you're getting? - Trip

1 Answers

6
votes

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))