ruby-changes:17993
From: naruse <ko1@a...>
Date: Thu, 2 Dec 2010 10:46:52 +0900 (JST)
Subject: [ruby-changes:17993] Ruby:r30014 (trunk): * lib/net/http.rb (Net::HTTP#set_form_data):
naruse 2010-12-02 10:46:45 +0900 (Thu, 02 Dec 2010) New Revision: 30014 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30014 Log: * lib/net/http.rb (Net::HTTP#set_form_data): use URI.encode_www_form for application/x-www-form-urlencoded. Modified files: trunk/ChangeLog trunk/lib/net/http.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 30013) +++ ChangeLog (revision 30014) @@ -1,3 +1,8 @@ +Thu Dec 2 10:39:39 2010 NARUSE, Yui <naruse@r...> + + * lib/net/http.rb (Net::HTTP#set_form_data): + use URI.encode_www_form for application/x-www-form-urlencoded. + Thu Dec 2 10:38:40 2010 NARUSE, Yui <naruse@r...> * ext/extmk.rb: remove $makeflags.defined?, it should be $mflags. Index: lib/net/http.rb =================================================================== --- lib/net/http.rb (revision 30013) +++ lib/net/http.rb (revision 30014) @@ -1784,22 +1784,14 @@ # http.set_form_data({"q" => "ruby", "lang" => "en"}, ';') # def set_form_data(params, sep = '&') - self.body = params.map {|k, v| encode_kvpair(k, v) }.flatten.join(sep) + query = URI.encode_www_form(params) + query.gsub!(/&/, sep) if sep != '&' + self.body = query self.content_type = 'application/x-www-form-urlencoded' end alias form_data= set_form_data - def encode_kvpair(k, vs) - Array(vs).map {|v| "#{urlencode(k.to_s)}=#{urlencode(v.to_s)}" } - end - private :encode_kvpair - - def urlencode(str) - str.dup.force_encoding('ASCII-8BIT').gsub(/[^a-zA-Z0-9_\.\-]/){'%%%02x' % $&.ord} - end - private :urlencode - # Set the Authorization: header for "Basic" authorization. def basic_auth(account, password) @header['authorization'] = [basic_encode(account, password)] -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/