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
Updated by naruse (Yui NARUSE) about 14 years ago
=begin
なかださんによる、http://www.atdot.net/sp/raw/7hhs9l のパッチの方がforce_encodingの適用が1回なのでよいかと思います。
=end
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