зеркало из https://github.com/github/ruby.git
[ruby/cgi] Add test for escapeHTML/unescapeHTML invalid encoding fix in pure ruby version
Also, remove pointless assert_nothing_raised(ArgumentError) while here. https://github.com/ruby/cgi/commit/c05edf5608
This commit is contained in:
Родитель
2756938369
Коммит
f818b1ed2b
|
@ -36,9 +36,7 @@ class CGIUtilTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_cgi_escape_with_invalid_byte_sequence
|
||||
assert_nothing_raised(ArgumentError) do
|
||||
assert_equal('%C0%3C%3C', CGI.escape("\xC0\<\<".dup.force_encoding("UTF-8")))
|
||||
end
|
||||
assert_equal('%C0%3C%3C', CGI.escape("\xC0\<\<".dup.force_encoding("UTF-8")))
|
||||
end
|
||||
|
||||
def test_cgi_escape_preserve_encoding
|
||||
|
@ -191,3 +189,32 @@ class CGIUtilTest < Test::Unit::TestCase
|
|||
assert_equal('<BR><A HREF="url"></A>', unescape_element(escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"]))
|
||||
end
|
||||
end
|
||||
|
||||
class CGIUtilPureRubyTest < Test::Unit::TestCase
|
||||
def setup
|
||||
CGI::Escape.module_eval do
|
||||
alias _escapeHTML escapeHTML
|
||||
remove_method :escapeHTML
|
||||
alias _unescapeHTML unescapeHTML
|
||||
remove_method :unescapeHTML
|
||||
end
|
||||
end
|
||||
|
||||
def teardown
|
||||
CGI::Escape.module_eval do
|
||||
alias escapeHTML _escapeHTML
|
||||
remove_method :_escapeHTML
|
||||
alias unescapeHTML _unescapeHTML
|
||||
remove_method :_unescapeHTML
|
||||
end
|
||||
end
|
||||
|
||||
def test_cgi_escapeHTML_with_invalid_byte_sequence
|
||||
assert_equal("<\xA4??>", CGI.escapeHTML(%[<\xA4??>]))
|
||||
end
|
||||
|
||||
def test_cgi_unescapeHTML_with_invalid_byte_sequence
|
||||
input = "\xFF&"
|
||||
assert_equal(input, CGI.unescapeHTML(input))
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче