File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -233,11 +233,23 @@ in your helpers as follows:
233233 def h(text)
234234 Rack::Utils.escape_html(text)
235235 end
236+
237+ def hattr(text)
238+ Rack::Utils.escape_path(text)
239+ end
236240 end
237241
238- Now you can escape HTML in your templates like this:
242+ Now you can escape HTML entities inside outputted text in your templates in one of two ways:
243+
244+ <div><%= h scary_output %></div>
245+
246+ or using the ` <%== ` feature:
247+
248+ <div><%== scary_output %></div>
249+
250+ And you can escape text inside element attributes in your templates like this:
239251
240- <%= h scary_output %>
252+ <a href="< %= hattr scary_output %>" >A nice safe link!</a >
241253
242254Thanks to [ Chris Schneider] ( http://www.gittr.com/index.php/archive/using-rackutils-in-sinatra-escape_html-h-in-rails/ )
243255for the tip!
You can’t perform that action at this time.
0 commit comments