Skip to content

Commit c05edf5

Browse files
committed
Add test for escapeHTML/unescapeHTML invalid encoding fix in pure ruby version
Also, remove pointless assert_nothing_raised(ArgumentError) while here.
1 parent 2b1c2e2 commit c05edf5

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

test/cgi/test_cgi_util.rb

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ def test_cgi_escape_with_unreserved_characters
3636
end
3737

3838
def test_cgi_escape_with_invalid_byte_sequence
39-
assert_nothing_raised(ArgumentError) do
40-
assert_equal('%C0%3C%3C', CGI.escape("\xC0\<\<".dup.force_encoding("UTF-8")))
41-
end
39+
assert_equal('%C0%3C%3C', CGI.escape("\xC0\<\<".dup.force_encoding("UTF-8")))
4240
end
4341

4442
def test_cgi_escape_preserve_encoding
@@ -191,3 +189,32 @@ def test_cgi_unescapeElement
191189
assert_equal('&lt;BR&gt;<A HREF="url"></A>', unescape_element(escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"]))
192190
end
193191
end
192+
193+
class CGIUtilPureRubyTest < Test::Unit::TestCase
194+
def setup
195+
CGI::Escape.module_eval do
196+
alias _escapeHTML escapeHTML
197+
remove_method :escapeHTML
198+
alias _unescapeHTML unescapeHTML
199+
remove_method :unescapeHTML
200+
end
201+
end
202+
203+
def teardown
204+
CGI::Escape.module_eval do
205+
alias escapeHTML _escapeHTML
206+
remove_method :_escapeHTML
207+
alias unescapeHTML _unescapeHTML
208+
remove_method :_unescapeHTML
209+
end
210+
end
211+
212+
def test_cgi_escapeHTML_with_invalid_byte_sequence
213+
assert_equal("&lt;\xA4??&gt;", CGI.escapeHTML(%[<\xA4??>]))
214+
end
215+
216+
def test_cgi_unescapeHTML_with_invalid_byte_sequence
217+
input = "\xFF&"
218+
assert_equal(input, CGI.unescapeHTML(input))
219+
end
220+
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy