Project

General

Profile

ActionsLike0

Bug #3909

closed

CGI.unescape("あ%E3%81%82")で例外

Added by xibbar (Takeyuki FUJIOKA) about 14 years ago. Updated over 13 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
Backport:
[ruby-dev:42339]

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

#2

Updated by xibbar (Takeyuki FUJIOKA) about 14 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100
ActionsLike0

Also available in: Atom PDF