Skip to content

Commit

Permalink
Array parameters should not contain nil values.
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jun 11, 2012
1 parent 8355abf commit f4174ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions actionpack/lib/action_dispatch/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,19 @@ def local?

# Remove nils from the params hash
def deep_munge(hash)
keys = hash.keys.find_all { |k| hash[k] == [nil] }
keys.each { |k| hash[k] = nil }

hash.each_value do |v|
case v
when Array
v.grep(Hash) { |x| deep_munge(x) }
v.compact!
when Hash
deep_munge(v)
end
end

keys = hash.keys.find_all { |k| hash[k] == [nil] }
keys.each { |k| hash[k] = nil }
hash
end

Expand Down
4 changes: 4 additions & 0 deletions actionpack/test/dispatch/request/query_string_parsing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def teardown
assert_parses({"action"=>{"foo"=>[{"bar"=>nil}]}}, "action[foo][][bar]")
end

def test_array_parses_without_nil
assert_parses({"action" => ['1']}, "action[]=1&action[]")
end

test "query string with empty key" do
assert_parses(
{ "action" => "create_customer", "full_name" => "David Heinemeier Hansson" },
Expand Down

0 comments on commit f4174ad

Please sign in to comment.