require File.expand_path("../../helper", __FILE__)
class HtmlEscapeTest < MiniTest::Unit::TestCase
def test_escape_basic_html_with_secure
assert_equal "<some_tag/>", EscapeUtils.escape_html("")
secure_before = EscapeUtils.html_secure
EscapeUtils.html_secure = true
assert_equal "<some_tag/>", EscapeUtils.escape_html("")
EscapeUtils.html_secure = secure_before
end
def test_escape_basic_html_without_secure
assert_equal "<some_tag/>", EscapeUtils.escape_html("", false)
secure_before = EscapeUtils.html_secure
EscapeUtils.html_secure = false
assert_equal "<some_tag/>", EscapeUtils.escape_html("")
EscapeUtils.html_secure = secure_before
end
def test_escape_double_quotes
assert_equal "<some_tag some_attr="some value"/>", EscapeUtils.escape_html("")
end
def test_escape_single_quotes
assert_equal "<some_tag some_attr='some value'/>", EscapeUtils.escape_html("")
end
def test_escape_ampersand
assert_equal "<b>Bourbon & Branch</b>", EscapeUtils.escape_html("Bourbon & Branch")
end
def test_returns_original_if_not_escaped
str = 'foobar'
assert_equal str.object_id, EscapeUtils.escape_html(str).object_id
end
if RUBY_VERSION =~ /^1.9/
def test_utf8_or_ascii_input_only
str = "Bourbon & Branch"
str.force_encoding 'ISO-8859-1'
assert_raises Encoding::CompatibilityError do
EscapeUtils.escape_html(str)
end
str.force_encoding 'UTF-8'
begin
EscapeUtils.escape_html(str)
rescue Encoding::CompatibilityError => e
assert_nil e, "#{e.class.name} raised, expected not to"
end
end
def test_return_value_is_tagged_as_utf8
str = "Bourbon & Branch".encode('utf-8')
assert_equal Encoding.find('UTF-8'), EscapeUtils.escape_html(str).encoding
end
end
end