-
-
Save spastorino/7375c064765c35ec6b23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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