summary refs log tree commit
diff options
context:
space:
mode:
authorJames Tucker <jftucker@gmail.com>2014-08-03 14:15:10 -0300
committerJames Tucker <jftucker@gmail.com>2014-08-03 14:15:10 -0300
commitc34b5790af6733571522adf7cc91e9e85c4a3b64 (patch)
treeda13e7760ca450b93621eb1bc68697428d1d22f2
parent60a25f2c26b764aefc882f197f8b2af248b405d2 (diff)
downloadrack-c34b5790af6733571522adf7cc91e9e85c4a3b64.tar.gz
build_nested_query includes integer values
Patch from @spastorino
Closes #557
-rw-r--r--lib/rack/utils.rb6
-rw-r--r--test/spec_utils.rb2
2 files changed, 5 insertions, 3 deletions
diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb
index 53303995..d5a19914 100644
--- a/lib/rack/utils.rb
+++ b/lib/rack/utils.rb
@@ -179,11 +179,11 @@ module Rack
         value.map { |k, v|
           build_nested_query(v, prefix ? "#{prefix}[#{escape(k)}]" : escape(k))
         }.join("&")
-      when String
+      when nil
+        prefix
+      else
         raise ArgumentError, "value must be a Hash" if prefix.nil?
         "#{prefix}=#{escape(value)}"
-      else
-        prefix
       end
     end
     module_function :build_nested_query
diff --git a/test/spec_utils.rb b/test/spec_utils.rb
index 4b989db7..53311fd2 100644
--- a/test/spec_utils.rb
+++ b/test/spec_utils.rb
@@ -248,6 +248,8 @@ describe Rack::Utils do
 
     Rack::Utils.build_nested_query("foo" => "1", "bar" => "2").
       should.be equal_query_to("foo=1&bar=2")
+    Rack::Utils.build_nested_query("foo" => 1, "bar" => 2).
+      should.be equal_query_to("foo=1&bar=2")
     Rack::Utils.build_nested_query("my weird field" => "q1!2\"'w$5&7/z8)?").
       should.be equal_query_to("my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F")