Bug #3909

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

Added by Takeyuki FUJIOKA almost 5 years ago. Updated about 4 years ago.

[ruby-dev:42339]
Status:Closed
Priority:Normal
Assignee:Takeyuki FUJIOKA
ruby -v:ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0] Backport:

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

Associated revisions

Revision 29484
Added by Takeyuki FUJIOKA almost 5 years ago

  • lib/cgi/util.rb (CGI::unescape): bugfix to unescape the multibyte string. Thanks nobu and tDiary dev members. [Bug #3909]

Revision 29484
Added by Takeyuki FUJIOKA almost 5 years ago

  • lib/cgi/util.rb (CGI::unescape): bugfix to unescape the multibyte string. Thanks nobu and tDiary dev members. [Bug #3909]

History

#1 Updated by Yui NARUSE almost 5 years ago

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

#2 Updated by Takeyuki FUJIOKA almost 5 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

Also available in: Atom PDF