Rails 3 关于 Sanitize Gem 功能的问题

发布于 2024-11-27 07:54:57 字数 779 浏览 5 评论 0原文

我是一个相对 Rails 的新手,对消毒宝石有疑问。它很容易安装和使用,但由于某种原因,当我选择拥有自己的元素数组时,它不起作用。它仍在清理我试图批准的元素。这是我的代码:

def scrub(html)  
 # Setup whitelist of html elements that are allowed.
 allowed_elements = ['b', 'blockquote', 'em', 'i', 'li', 'ol', 'p', 'pre', 'u', 'ul']
 Sanitize.clean(html, :elements => allowed_elements)
end

但结果显示以下内容:

<p> And Some Content... &lt;script&gt;mal&lt;/script&gt; 
and <em>italics and bold</em></p> 
<ol> <li> list</li> <li> list</li> </ol>
<blockquote> <p> blockquote</p> </blockquote> 
<ul> <li> bullet</li> <li> bullet</li> </ul>

感谢您提供有关为什么这种简单格式不起作用的任何指示!

I'm a relative rails newbie and have a question about the sanitize gem. It is easy to install and use, but for some reason when I choose to have my own elements array, it isn't working. It is still sanitizing the elements I'm trying to approve. Here's my code:

def scrub(html)  
 # Setup whitelist of html elements that are allowed.
 allowed_elements = ['b', 'blockquote', 'em', 'i', 'li', 'ol', 'p', 'pre', 'u', 'ul']
 Sanitize.clean(html, :elements => allowed_elements)
end

but it is showing the following as a result:

<p> And Some Content... <script>mal</script> 
and <em>italics and bold</em></p> 
<ol> <li> list</li> <li> list</li> </ol>
<blockquote> <p> blockquote</p> </blockquote> 
<ul> <li> bullet</li> <li> bullet</li> </ul>

thanks for any pointers about why this simple format isn't working!

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

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

发布评论

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

评论(1

§对你不离不弃 2024-12-04 07:54:57
def scrub(html)  
 # Setup whitelist of html elements that are allowed.
 allowed_elements = ['b', 'blockquote', 'em', 'i', 'li', 'ol', 'p', 'pre', 'u', 'ul']
 Sanitize.clean(html, :elements => allowed_elements).html_safe
end
def scrub(html)  
 # Setup whitelist of html elements that are allowed.
 allowed_elements = ['b', 'blockquote', 'em', 'i', 'li', 'ol', 'p', 'pre', 'u', 'ul']
 Sanitize.clean(html, :elements => allowed_elements).html_safe
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文