Skip to content

Commit

Permalink
[format_helpers] Mark escaped text as html_safe (Closes #1183)
Browse files Browse the repository at this point in the history
  • Loading branch information
nesquena committed Mar 25, 2013
1 parent 9df9849 commit 9a2452c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions padrino-helpers/lib/padrino-helpers/format_helpers.rb
Expand Up @@ -19,7 +19,7 @@ module FormatHelpers
#
# @api public
def escape_html(text)
Rack::Utils.escape_html(text)
Rack::Utils.escape_html(text).html_safe
end
alias h escape_html
alias sanitize_html escape_html
Expand All @@ -41,8 +41,8 @@ def escape_html(text)
#
# @api public
def h!(text, blank_text = ' ')
return blank_text if text.nil? || text.empty?
h text
return blank_text.html_safe if text.nil? || text.empty?
h(text)
end

##
Expand Down
5 changes: 5 additions & 0 deletions padrino-helpers/test/test_format_helpers.rb
Expand Up @@ -139,6 +139,11 @@ def setup
should "return text escaped if not empty" do
assert_equal '&lt;h1&gt;hello&lt;&#x2F;h1&gt;', h!('<h1>hello</h1>')
end
should "mark escaped text as safe" do
assert_equal false, '<h1>hello</h1>'.html_safe?
assert_equal true, h('<h1>hello</h1>').html_safe?
assert_equal true, h!("", "default").html_safe?
end
end

context 'for #time_ago_in_words method' do
Expand Down

0 comments on commit 9a2452c

Please sign in to comment.