ruby-changes:17479
From: xibbar <ko1@a...>
Date: Wed, 13 Oct 2010 22:39:23 +0900 (JST)
Subject: [ruby-changes:17479] Ruby:r29484 (trunk): * lib/cgi/util.rb (CGI::unescape): bugfix to unescape the multibyte
xibbar 2010-10-13 22:39:13 +0900 (Wed, 13 Oct 2010) New Revision: 29484 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29484 Log: * lib/cgi/util.rb (CGI::unescape): bugfix to unescape the multibyte string. Thanks nobu and tDiary dev members. [Bug #3909] Modified files: trunk/ChangeLog trunk/lib/cgi/util.rb trunk/test/cgi/test_cgi_util.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 29483) +++ ChangeLog (revision 29484) @@ -1,3 +1,8 @@ +Wed Oct 13 22:32:34 2010 Takeyuki FUJIOKA <xibbar@r...> + + * lib/cgi/util.rb (CGI::unescape): bugfix to unescape the multibyte + string. Thanks nobu and tDiary dev members. [Bug #3909] + Wed Oct 13 21:13:00 2010 NARUSE, Yui <naruse@r...> * numeric.c (int_chr): raise error when the value is negative. Index: lib/cgi/util.rb =================================================================== --- lib/cgi/util.rb (revision 29483) +++ lib/cgi/util.rb (revision 29484) @@ -14,7 +14,7 @@ # string = CGI::unescape("%27Stop%21%27+said+Fred") # # => "'Stop!' said Fred" def CGI::unescape(string,encoding=@@accept_charset) - str=string.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/) do + str=string.tr('+', ' ').force_encoding(Encoding::ASCII_8BIT).gsub(/((?:%[0-9a-fA-F]{2})+)/) do [$1.delete('%')].pack('H*') end.force_encoding(encoding) str.valid_encoding? ? str : str.force_encoding(string.encoding) Index: test/cgi/test_cgi_util.rb =================================================================== --- test/cgi/test_cgi_util.rb (revision 29483) +++ test/cgi/test_cgi_util.rb (revision 29484) @@ -27,6 +27,7 @@ def test_cgi_unescape assert_equal(@str1, CGI::unescape('%26%3C%3E%22+%E3%82%86%E3%82%93%E3%82%86%E3%82%93')) assert_equal(@str1.encoding, CGI::unescape('%26%3C%3E%22+%E3%82%86%E3%82%93%E3%82%86%E3%82%93').encoding) if defined?(::Encoding) + assert_equal("\u{30E1 30E2 30EA 691C 7D22}", CGI.unescape("\u{30E1 30E2 30EA}%E6%A4%9C%E7%B4%A2")) end def test_cgi_pretty -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/