2008-05-17 23:22:34 -05:00
|
|
|
require 'abstract_unit'
|
2007-12-21 01:48:59 -06:00
|
|
|
|
|
|
|
class ErbUtilTest < Test::Unit::TestCase
|
|
|
|
include ERB::Util
|
|
|
|
|
2008-05-17 23:22:34 -05:00
|
|
|
ERB::Util::HTML_ESCAPE.each do |given, expected|
|
|
|
|
define_method "test_html_escape_#{expected.gsub /\W/, ''}" do
|
|
|
|
assert_equal expected, html_escape(given)
|
2007-12-21 01:48:59 -06:00
|
|
|
end
|
|
|
|
|
2008-05-17 23:22:34 -05:00
|
|
|
unless given == '"'
|
|
|
|
define_method "test_json_escape_#{expected.gsub /\W/, ''}" do
|
|
|
|
assert_equal ERB::Util::JSON_ESCAPE[given], json_escape(given)
|
|
|
|
end
|
|
|
|
end
|
2007-12-21 01:48:59 -06:00
|
|
|
end
|
2010-05-25 12:45:45 -05:00
|
|
|
|
|
|
|
def test_html_escape_is_html_safe
|
|
|
|
escaped = h("<p>")
|
|
|
|
assert_equal "<p>", escaped
|
|
|
|
assert escaped.html_safe?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_html_escape_passes_html_escpe_unmodified
|
|
|
|
escaped = h("<p>".html_safe)
|
|
|
|
assert_equal "<p>", escaped
|
|
|
|
assert escaped.html_safe?
|
|
|
|
end
|
2007-12-21 01:48:59 -06:00
|
|
|
|
|
|
|
def test_rest_in_ascii
|
|
|
|
(0..127).to_a.map(&:chr).each do |chr|
|
|
|
|
next if %w(& " < >).include?(chr)
|
|
|
|
assert_equal chr, html_escape(chr)
|
|
|
|
end
|
|
|
|
end
|
2008-05-17 23:22:34 -05:00
|
|
|
end
|