ruby-changes:65923
From: Jeremy <ko1@a...>
Date: Thu, 22 Apr 2021 11:52:00 +0900 (JST)
Subject: [ruby-changes:65923] f818b1ed2b (master): [ruby/cgi] Add test for escapeHTML/unescapeHTML invalid encoding fix in pure ruby version
https://git.ruby-lang.org/ruby.git/commit/?id=f818b1ed2b From f818b1ed2b2ec16bbc55919082d6cafb99693db8 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Thu, 25 Feb 2021 09:24:15 -0800 Subject: [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 --- test/cgi/test_cgi_util.rb | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/test/cgi/test_cgi_util.rb b/test/cgi/test_cgi_util.rb index b7bb7b8..6ce8b42 100644 --- a/test/cgi/test_cgi_util.rb +++ b/test/cgi/test_cgi_util.rb @@ -36,9 +36,7 @@ class CGIUtilTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_util.rb#L36 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 https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_util.rb#L189 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 -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/