Skip to content

Instantly share code, notes, and snippets.

@spastorino
Created May 16, 2013 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spastorino/7375c064765c35ec6b23 to your computer and use it in GitHub Desktop.
Save spastorino/7375c064765c35ec6b23 to your computer and use it in GitHub Desktop.
diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb
index 0c7091e..30dc81d 100644
--- a/lib/rack/utils.rb
+++ b/lib/rack/utils.rb
@@ -158,11 +158,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 622b8ff..0bb228e 100644
--- a/test/spec_utils.rb
+++ b/test/spec_utils.rb
@@ -221,6 +221,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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment