使用 < 来清理宝石问题和>

发布于 2024-12-19 13:44:19 字数 629 浏览 3 评论 0 原文

我正在使用 sanitize gem https://github.com/rgrove/sanitize 来删除一些 HTML 标签一个字符串。

但是,在清理控制器中的字符串之前,该字符串被设置如下:

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

这意味着 <和>被 <&gt; 取代。

当这些标签表示为 &lt;i&gt;&lt;/ 时,如何使用 sanitize gem 删除例如 i> 在控制器中?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┾廆蒐ゝ 2024-12-26 13:44:19

如果您希望转义的 HTML 标签(< 和 >)被视为 HTML 以便进行清理,那么您必须首先对它们进行转义:

require 'cgi'
Sanitize.clean(CGI.unescapeHTML(your_string))

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))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文