Skip to content

Commit

Permalink
html_escape is not Rails specific
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsuda committed Nov 15, 2017
1 parent a7b75aa commit 6d78383
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
21 changes: 21 additions & 0 deletions test/helper_test.rb
Expand Up @@ -338,6 +338,27 @@ def obj.something_that_uses_haml_concat
assert_equal __LINE__ - 6, e.backtrace[0].scan(/:(\d+)/).first.first.to_i
end

def test_html_escape
assert_equal "&quot;&gt;&lt;&amp;", Haml::Helpers.html_escape('"><&')
end

def test_html_escape_should_work_on_frozen_strings
begin
assert Haml::Helpers.html_escape('foo'.freeze)
rescue => e
flunk e.message
end
end

def test_html_escape_encoding
old_stderr, $stderr = $stderr, StringIO.new
string = "\"><&\u00e9" # if you're curious, u00e9 is "LATIN SMALL LETTER E WITH ACUTE"
assert_equal "&quot;&gt;&lt;&amp;\u00e9", Haml::Helpers.html_escape(string)
assert $stderr.string == "", "html_escape shouldn't generate warnings with UTF-8 strings: #{$stderr.string}"
ensure
$stderr = old_stderr
end

def test_html_escape_non_string
assert_equal('4.58', Haml::Helpers.html_escape(4.58))
assert_equal('4.58', Haml::Helpers.html_escape_without_haml_xss(4.58))
Expand Down
21 changes: 0 additions & 21 deletions test/helpers_for_rails_test.rb
Expand Up @@ -276,25 +276,4 @@ def test_capture_with_nuke_outer
%div> hi there!
HAML
end

def test_html_escape
assert_equal "&quot;&gt;&lt;&amp;", Haml::Helpers.html_escape('"><&')
end

def test_html_escape_should_work_on_frozen_strings
begin
assert Haml::Helpers.html_escape('foo'.freeze)
rescue => e
flunk e.message
end
end

def test_html_escape_encoding
old_stderr, $stderr = $stderr, StringIO.new
string = "\"><&\u00e9" # if you're curious, u00e9 is "LATIN SMALL LETTER E WITH ACUTE"
assert_equal "&quot;&gt;&lt;&amp;\u00e9", Haml::Helpers.html_escape(string)
assert $stderr.string == "", "html_escape shouldn't generate warnings with UTF-8 strings: #{$stderr.string}"
ensure
$stderr = old_stderr
end
end

0 comments on commit 6d78383

Please sign in to comment.