Actions
Bug #3909
closedCGI.unescape("あ%E3%81%82")で例外
Description
=begin
tDiaryの方で例外が起きるという報告がありました。
irb(main):004:0> CGI.unescape("あ%E3%81%82")
Encoding::CompatibilityError: incompatible character encodings: UTF-8
and ASCII-8BIT
from /usr/local/ruby-trunk/lib/ruby/1.9.1/cgi/util.rb:17:in gsub' from /usr/local/ruby-trunk/lib/ruby/1.9.1/cgi/util.rb:17:in
unescape'
from (irb):4
from /usr/local/ruby-trunk/bin/irb-trunk:12:in `'
かずひこさんによると、
--- cgi/util.rb.orig
+++ cgi/util.rb
@@ -15,8 +15,8 @@
# # => "'Stop!' said Fred"
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)
-
[$1.delete('%')].pack('H*').force_encoding(encoding)
- end
str.valid_encoding? ? str : str.force_encoding(string.encoding)
end
でなおるとのことです。
=end
Actions
Like0
Like0Like0