diff options
author | xibbar <xibbar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-07-30 05:34:02 +0000 |
---|---|---|
committer | xibbar <xibbar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-07-30 05:34:02 +0000 |
commit | 1976ef38a7630addb63689053b6dc1d4889d934d (patch) | |
tree | 421dc7a33bfe1ca30362f58fdc76ed6c352828a2 /lib/cgi/util.rb | |
parent | 3ca25b5a292edfee968d64aac686b46265cad5b5 (diff) | |
download | ruby-1976ef38a7630addb63689053b6dc1d4889d934d.tar.gz |
* 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.rb | 12 |
1 files changed, 6 insertions, 6 deletions
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__ = { |