* lib/uri/common.rb (URI.encode_www_form):

split key-value when the value is Array like object.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2010-12-02 04:33:56 +00:00
Родитель f5bdc774fd
Коммит e41ed50bf0
2 изменённых файлов: 26 добавлений и 3 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Thu Dec 2 13:10:42 2010 NARUSE, Yui <naruse@ruby-lang.org>
* lib/uri/common.rb (URI.encode_www_form):
split key-value when the value is Array like object.
Thu Dec 2 10:39:39 2010 NARUSE, Yui <naruse@ruby-lang.org>
* lib/net/http.rb (Net::HTTP#set_form_data):

Просмотреть файл

@ -798,15 +798,33 @@ module URI
# This is an implementation of
# http://www.w3.org/TR/html5/forms.html#url-encoded-form-data
#
# URI.encode_www_form([["q", "ruby"], ["lang", "en"]])
# #=> "q=ruby&lang=en"
# URI.encode_www_form("q" => "ruby", "lang" => "en")
# #=> "q=ruby&lang=en"
# URI.encode_www_form("q" => ["ruby", "perl"], "lang" => "en")
# #=> "q=ruby&q=perl&lang=en"
# URI.encode_www_form([["q", "ruby"], ["q", "perl"], ["lang", "en"]])
# #=> "q=ruby&q=perl&lang=en"
#
# See URI.encode_www_form_component, URI.decode_www_form
def self.encode_www_form(enum)
enum.map do |k,v|
str = encode_www_form_component(k)
if v
if v.nil?
encode_www_form_component(k)
elsif v.respond_to?(:to_ary)
v.to_ary.map do |w|
str = encode_www_form_component(k)
unless w.nil?
str << '='
str << encode_www_form_component(w)
end
end.join('&')
else
str = encode_www_form_component(k)
str << '='
str << encode_www_form_component(v)
end
str
end.join('&')
end