ruby-changes:30219
From: sorah <ko1@a...>
Date: Wed, 31 Jul 2013 18:00:35 +0900 (JST)
Subject: [ruby-changes:30219] sorah:r42271 (trunk): * lib/uri/common.rb (URI.decode_www_form_component):
sorah 2013-07-31 18:00:18 +0900 (Wed, 31 Jul 2013) New Revision: 42271 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42271 Log: * lib/uri/common.rb (URI.decode_www_form_component): Don't raise error when str includes multibyte characters. Modified files: trunk/ChangeLog trunk/lib/uri/common.rb trunk/test/uri/test_common.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 42270) +++ ChangeLog (revision 42271) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Jul 31 17:55:55 2013 Shota Fukumori <her@s...> + + * lib/uri/common.rb (URI.decode_www_form_component): + Don't raise error when str includes multibyte characters. + Wed Jul 31 17:45:39 2013 Masaki Matsushita <glass.saga@g...> * string.c (rb_str_rindex): performance improvement by using Index: lib/uri/common.rb =================================================================== --- lib/uri/common.rb (revision 42270) +++ lib/uri/common.rb (revision 42271) @@ -899,7 +899,9 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb#L899 # See URI.encode_www_form_component, URI.decode_www_form def self.decode_www_form_component(str, enc=Encoding::UTF_8) raise ArgumentError, "invalid %-encoding (#{str})" unless /\A[^%]*(?:%\h\h[^%]*)*\z/ =~ str - str.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc) + str.dup.force_encoding("ASCII-8BIT") \ + .gsub(/\+|%\h\h/, TBLDECWWWCOMP_) \ + .force_encoding(enc) end # Generate URL-encoded form data from given +enum+. Index: test/uri/test_common.rb =================================================================== --- test/uri/test_common.rb (revision 42270) +++ test/uri/test_common.rb (revision 42271) @@ -91,6 +91,9 @@ class TestCommon < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/uri/test_common.rb#L91 "AZ%5B%5C%5D%5E_%60az%7B%7C%7D%7E")) assert_equal("\xA1\xA2".force_encoding(Encoding::EUC_JP), URI.decode_www_form_component("%A1%A2", "EUC-JP")) + assert_equal("\xE3\x81\x82\xE3\x81\x82".force_encoding("UTF-8"), + URI.decode_www_form_component("\xE3\x81\x82%E3%81%82".force_encoding("UTF-8"))) + assert_raise(ArgumentError){URI.decode_www_form_component("%")} end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/