Skip to content

Commit 653e7d4

Browse files
committed
handle invalid encoding
1 parent d7ec8e0 commit 653e7d4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/cgi/util.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ def escapeHTML(string)
4949
table = Hash[TABLE_FOR_ESCAPE_HTML__.map {|pair|pair.map {|s|s.encode(enc)}}]
5050
string = string.gsub(/#{"['&\"<>]".encode(enc)}/, table)
5151
string.encode!(origenc) if origenc
52-
return string
52+
string
53+
else
54+
string = string.b
55+
string.gsub!(/['&\"<>]/, TABLE_FOR_ESCAPE_HTML__)
56+
string.force_encoding(enc)
5357
end
54-
string.gsub(/['&\"<>]/, TABLE_FOR_ESCAPE_HTML__)
5558
end
5659

5760
begin

0 commit comments

Comments
 (0)