From 64fbf680815f596149d8c13c4a7f83d6b2c3c701 Mon Sep 17 00:00:00 2001 From: Tobias Pfeiffer Date: Tue, 21 Jul 2020 08:59:29 +0200 Subject: [PATCH] Parsing behavior change from foo[] to "foo" => [] Pending discussion in #1696 and if merged also fixes #1696 --- lib/rack/query_parser.rb | 2 +- test/spec_utils.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rack/query_parser.rb b/lib/rack/query_parser.rb index dbbb18e5a..cbde13cfd 100644 --- a/lib/rack/query_parser.rb +++ b/lib/rack/query_parser.rb @@ -102,7 +102,7 @@ def normalize_params(params, name, v, depth) elsif after == "[]" params[k] ||= [] raise ParameterTypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array) - params[k] << v + params[k] << v unless v.nil? elsif after =~ %r(^\[\]\[([^\[\]]+)\]$) || after =~ %r(^\[\](.+)$) child_key = $1 params[k] ||= [] diff --git a/test/spec_utils.rb b/test/spec_utils.rb index 428abbfd7..d06a3c715 100644 --- a/test/spec_utils.rb +++ b/test/spec_utils.rb @@ -162,7 +162,7 @@ def assert_nested_query(exp, act) must_equal "pid=1234" => "1023", "a" => "b" Rack::Utils.parse_nested_query("foo[]"). - must_equal "foo" => [nil] + must_equal "foo" => [] Rack::Utils.parse_nested_query("foo[]="). must_equal "foo" => [""] Rack::Utils.parse_nested_query("foo[]=bar"). @@ -174,7 +174,7 @@ def assert_nested_query(exp, act) Rack::Utils.parse_nested_query("foo[]=bar&foo[=baz"). must_equal "foo" => ["bar"], "foo[" => "baz" Rack::Utils.parse_nested_query("foo[]=bar&foo[]"). - must_equal "foo" => ["bar", nil] + must_equal "foo" => ["bar"] Rack::Utils.parse_nested_query("foo[]=bar&foo[]="). must_equal "foo" => ["bar", ""]