зеркало из https://github.com/github/ruby.git
* 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:
Родитель
f5bdc774fd
Коммит
e41ed50bf0
|
@ -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
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче