aboutsummaryrefslogtreecommitdiffstats
path: root/lib/uri
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-02 04:33:56 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-02 04:33:56 +0000
commite41ed50bf0b2a2f657b88b0a328331f91385d6c0 (patch)
treeba7af76fd66c1b84772f09306dfdfeff461cdd23 /lib/uri
parentf5bdc774fdb0dbb9f23d3b314db5177f01d80714 (diff)
downloadruby-e41ed50bf0b2a2f657b88b0a328331f91385d6c0.tar.gz
* 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
Diffstat (limited to 'lib/uri')
-rw-r--r--lib/uri/common.rb24
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index b23e971f5e..719dbca4b8 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -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