diff options
-rw-r--r-- | lib/rack/utils.rb | 2 | ||||
-rw-r--r-- | test/spec_utils.rb | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb index 53303995..691a4a6e 100644 --- a/lib/rack/utils.rb +++ b/lib/rack/utils.rb @@ -178,7 +178,7 @@ module Rack when Hash value.map { |k, v| build_nested_query(v, prefix ? "#{prefix}[#{escape(k)}]" : escape(k)) - }.join("&") + }.reject(&:empty?).join('&') when String raise ArgumentError, "value must be a Hash" if prefix.nil? "#{prefix}=#{escape(value)}" diff --git a/test/spec_utils.rb b/test/spec_utils.rb index 4b989db7..4ee2d03f 100644 --- a/test/spec_utils.rb +++ b/test/spec_utils.rb @@ -257,6 +257,14 @@ describe Rack::Utils do should.equal "foo[]=" Rack::Utils.build_nested_query("foo" => ["bar"]). should.equal "foo[]=bar" + Rack::Utils.build_nested_query('foo' => []). + should.equal '' + Rack::Utils.build_nested_query('foo' => {}). + should.equal '' + Rack::Utils.build_nested_query('foo' => 'bar', 'baz' => []). + should.equal 'foo=bar' + Rack::Utils.build_nested_query('foo' => 'bar', 'baz' => {}). + should.equal 'foo=bar' # The ordering of the output query string is unpredictable with 1.8's # unordered hash. Test that build_nested_query performs the inverse |