Skip to content
This repository
Browse code

Merge branch 'master-sec'

* master-sec:
  Array parameters should not contain nil values.
  • Loading branch information...
commit 2be40a873ecbbdc344b9933b9a6db80f7fead7f2 2 parents 6ff78a1 + 24894fc
Aaron Patterson authored June 12, 2012
6  actionpack/lib/action_dispatch/http/request.rb
@@ -267,17 +267,19 @@ def local?
267 267
 
268 268
     # Remove nils from the params hash
269 269
     def deep_munge(hash)
  270
+      keys = hash.keys.find_all { |k| hash[k] == [nil] }
  271
+      keys.each { |k| hash[k] = nil }
  272
+
270 273
       hash.each_value do |v|
271 274
         case v
272 275
         when Array
273 276
           v.grep(Hash) { |x| deep_munge(x) }
  277
+          v.compact!
274 278
         when Hash
275 279
           deep_munge(v)
276 280
         end
277 281
       end
278 282
 
279  
-      keys = hash.keys.find_all { |k| hash[k] == [nil] }
280  
-      keys.each { |k| hash[k] = nil }
281 283
       hash
282 284
     end
283 285
 
4  actionpack/test/dispatch/request/query_string_parsing_test.rb
@@ -89,6 +89,10 @@ def teardown
89 89
     assert_parses({"action"=>{"foo"=>[{"bar"=>nil}]}}, "action[foo][][bar]")
90 90
   end
91 91
 
  92
+  def test_array_parses_without_nil
  93
+    assert_parses({"action" => ['1']}, "action[]=1&action[]")
  94
+  end
  95
+
92 96
   test "query string with empty key" do
93 97
     assert_parses(
94 98
       { "action" => "create_customer", "full_name" => "David Heinemeier Hansson" },

0 notes on commit 2be40a8

Please sign in to comment.
Something went wrong with that request. Please try again.