新手问题 如何在 View 里面安全的解析 markdown

springwq · June 07, 2015 · Last by springwq replied at June 08, 2015 · 1927 hits

在 view 里面,我是这样解析 markdown 的:

<p>
  <%= render_markdown(post.description).html_safe %>
</p>

render_markdown 是一个 helper method

def render_markdown(text)
    Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(text)
 end

但是,post.description 里面有用户输入的任何数据,如果用了 html_safe 是不是有安全隐患?如何较安全的解析 Markdown 呢。

P.S. 看了 RubyChina 的源码,但是没看懂。。。。

#1 楼 @rei 谢谢!学习了 :plus1: , 越来越喜欢 Rails 了。

You need to Sign in before reply, if you don't have an account, please Sign up first.