Skip to content

Commit 2be40a8

Browse files
committed
Merge branch 'master-sec'
* master-sec: Array parameters should not contain nil values.
2 parents 6ff78a1 + 24894fc commit 2be40a8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

actionpack/lib/action_dispatch/http/request.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,17 +267,19 @@ def local?
267267

268268
# Remove nils from the params hash
269269
def deep_munge(hash)
270+
keys = hash.keys.find_all { |k| hash[k] == [nil] }
271+
keys.each { |k| hash[k] = nil }
272+
270273
hash.each_value do |v|
271274
case v
272275
when Array
273276
v.grep(Hash) { |x| deep_munge(x) }
277+
v.compact!
274278
when Hash
275279
deep_munge(v)
276280
end
277281
end
278282

279-
keys = hash.keys.find_all { |k| hash[k] == [nil] }
280-
keys.each { |k| hash[k] = nil }
281283
hash
282284
end
283285

actionpack/test/dispatch/request/query_string_parsing_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ def teardown
8989
assert_parses({"action"=>{"foo"=>[{"bar"=>nil}]}}, "action[foo][][bar]")
9090
end
9191

92+
def test_array_parses_without_nil
93+
assert_parses({"action" => ['1']}, "action[]=1&action[]")
94+
end
95+
9296
test "query string with empty key" do
9397
assert_parses(
9498
{ "action" => "create_customer", "full_name" => "David Heinemeier Hansson" },

0 commit comments

Comments
 (0)