mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Add tests for html_escape and escape_once
This commit is contained in:
parent
47c7dbfd37
commit
ffd54f64b5
1 changed files with 36 additions and 0 deletions
|
@ -458,5 +458,41 @@ HAML
|
|||
%div> hi there!
|
||||
HAML
|
||||
end
|
||||
|
||||
def test_html_escape
|
||||
assert_equal ""><&", Haml::Helpers.html_escape('"><&')
|
||||
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 ""><&\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_escape_once
|
||||
assert_equal ""><&", Haml::Helpers.escape_once('"><&')
|
||||
end
|
||||
|
||||
def test_escape_once_leaves_entity_references
|
||||
assert_equal ""><& ", Haml::Helpers.escape_once('"><& ')
|
||||
end
|
||||
|
||||
def test_escape_once_leaves_numeric_references
|
||||
assert_equal ""><&  ", Haml::Helpers.escape_once('"><&  ') #decimal
|
||||
#assert_equal ""><&  ", Haml::Helpers.escape_once('"><&  ') #hexadecimal
|
||||
end
|
||||
|
||||
def test_escape_once_encoding
|
||||
old_stderr, $stderr = $stderr, StringIO.new
|
||||
string = "\"><&\u00e9 "
|
||||
assert_equal ""><&\u00e9 ", Haml::Helpers.escape_once(string)
|
||||
assert $stderr.string == "", "html_escape shouldn't generate warnings with UTF-8 strings: #{$stderr.string}"
|
||||
ensure
|
||||
$stderr = old_stderr
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue