summaryrefslogtreecommitdiff
path: root/lib/cgi/util.rb
diff options
context:
space:
mode:
authorxibbar <xibbar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-30 05:34:02 +0000
committerxibbar <xibbar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-30 05:34:02 +0000
commit1976ef38a7630addb63689053b6dc1d4889d934d (patch)
tree421dc7a33bfe1ca30362f58fdc76ed6c352828a2 /lib/cgi/util.rb
parent3ca25b5a292edfee968d64aac686b46265cad5b5 (diff)
* lib/cgi/util.rb (CGI::unescape): support encoding option.
* lib/cgi/cookie.rb (CGI::Cookie.parse): fix for the encoded value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24314 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/cgi/util.rb')
-rw-r--r--lib/cgi/util.rb12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/cgi/util.rb b/lib/cgi/util.rb
index b7b0233b4d2..218bdbdd9a0 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__ = {