Project

General

Profile

Actions

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

Actions #1

Updated by naruse (Yui NARUSE) about 14 years ago

=begin
なかださんによる、http://www.atdot.net/sp/raw/7hhs9l のパッチの方がforce_encodingの適用が1回なのでよいかと思います。
=end

Actions #2

Updated by xibbar (Takeyuki FUJIOKA) about 14 years ago

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

=begin
This issue was solved with changeset r29484.
Takeyuki, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0