summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/cgi/cookie.rb2
-rw-r--r--lib/cgi/util.rb12
2 files changed, 7 insertions, 7 deletions
diff --git a/lib/cgi/cookie.rb b/lib/cgi/cookie.rb
index 5c2cd62a27..68fbc8972c 100644
--- a/lib/cgi/cookie.rb
+++ b/lib/cgi/cookie.rb
@@ -123,7 +123,7 @@ class CGI
next unless name and values
name = CGI::unescape(name)
values ||= ""
- values = values.split('&').collect{|v| CGI::unescape(v) }
+ values = values.split('&').collect{|v| CGI::unescape(v,@@accept_charset) }
if cookies.has_key?(name)
values = cookies[name].value + values
end
diff --git a/lib/cgi/util.rb b/lib/cgi/util.rb
index b7b0233b4d..218bdbdd9a 100644
--- a/lib/cgi/util.rb
+++ b/lib/cgi/util.rb
@@ -9,14 +9,14 @@ class CGI
end
- # URL-decode a string.
+ # URL-decode a string with encoding(optional).
# string = CGI::unescape("%27Stop%21%27+said+Fred")
# # => "'Stop!' said Fred"
- def CGI::unescape(string)
- enc = string.encoding
- string.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/) do
- [$1.delete('%')].pack('H*').force_encoding(enc)
- end
+ def CGI::unescape(string,encoding=@@accept_charset)
+ str=string.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/) do
+ [$1.delete('%')].pack('H*')
+ end.force_encoding(encoding)
+ str.valid_encoding? ? str : str.force_encoding(string.encoding)
end
TABLE_FOR_ESCAPE_HTML__ = {