开发者

How do I html_escape text data in a sinatra app?

I have a small Sinatra app which generates html fragments for me from an ERB template.

How do I html_escape the output?

The <%=h somestring %> 开发者_运维百科helper does not exist in Sinatra.


Rack::Utils includes a HTML escape method. http://www.sinatrarb.com/faq.html#escape_html


require 'CGI'

get '/html' do
  erb :view
end

def h(html)
  CGI.escapeHTML html
end

__END__
@@view
  <% File.open('my.html') do |f| %>
   <%=h f.read() %>
  <% end %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜