I have a small Sinatra app which generates html fragments for me from an ERB template.
我有一个小的Sinatra应用程序,它从ERB模板为我生成html片段。
How do I html_escape the output?
我如何html_escape输出?
The <%=h somestring %> helper does not exist in Sinatra.
Sinatra中不存在<%= h somestring%>帮助器。
2 个解决方案
#1
12
Rack::Utils
includes a HTML escape method. http://www.sinatrarb.com/faq.html#escape_html
Rack :: Utils包含一个HTML转义方法。 http://www.sinatrarb.com/faq.html#escape_html
#2
3
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 %>
#1
12
Rack::Utils
includes a HTML escape method. http://www.sinatrarb.com/faq.html#escape_html
Rack :: Utils包含一个HTML转义方法。 http://www.sinatrarb.com/faq.html#escape_html
#2
3
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 %>