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 d5a19914..69a96eb9 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 nil prefix else diff --git a/test/spec_utils.rb b/test/spec_utils.rb index 53311fd2..06ed5636 100644 --- a/test/spec_utils.rb +++ b/test/spec_utils.rb @@ -259,6 +259,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 |