Skip to content

Commit

Permalink
[ruby/cgi] Add failing test cases for CGI::Escape.unescapeHTML
Browse files Browse the repository at this point in the history
  • Loading branch information
flosacca authored and matzbot committed Nov 30, 2023
1 parent f2f9139 commit 0daa058
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/cgi/test_cgi_util.rb
Expand Up @@ -186,6 +186,22 @@ def test_cgi_unescapeHTML_invalid
assert_equal('&<&amp>&quot&abcdefghijklmn', CGI.unescapeHTML('&&lt;&amp&gt;&quot&abcdefghijklmn'))
end

module UnescapeHTMLTests
def test_cgi_unescapeHTML_following_known_first_letter
assert_equal('&a>&q>&l>&g>', CGI.unescapeHTML('&a&gt;&q&gt;&l&gt;&g&gt;'))
end

def test_cgi_unescapeHTML_following_number_sign
assert_equal('&#>&#x>', CGI.unescapeHTML('&#&gt;&#x&gt;'))
end

def test_cgi_unescapeHTML_following_invalid_numeric
assert_equal('&#1114112>&#x110000>', CGI.unescapeHTML('&#1114112&gt;&#x110000&gt;'))
end
end

include UnescapeHTMLTests

Encoding.list.each do |enc|
begin
escaped = "&#39;&amp;&quot;&gt;&lt;".encode(enc)
Expand Down Expand Up @@ -283,6 +299,8 @@ def teardown
end if defined?(CGI::Escape)
end

include CGIUtilTest::UnescapeHTMLTests

def test_cgi_escapeHTML_with_invalid_byte_sequence
assert_equal("&lt;\xA4??&gt;", CGI.escapeHTML(%[<\xA4??>]))
end
Expand Down

0 comments on commit 0daa058

Please sign in to comment.