aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--lib/uri/common.rb24
2 files changed, 26 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 7bde009e42..8a5d10ef60 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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):
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