Skip to content
Browse files

When a nil param value arrives in place of an expected hash, return

:key => nil, not simply nil.

Prior:

(rdb:1) params
{"book"=>nil}
(rdb:1) params.permit(book: { genre: :type })
nil

Now:

(rdb:1) params
{"book"=>nil}
(rdb:1) params.permit(book: { genre: :type })
{"book"=>nil}
  • Loading branch information...
1 parent 1e238a2 commit 7e9c635f4fcdf9ff6b0fd3af975b850c4014d305 @bjhess committed Apr 9, 2012
Showing with 8 additions and 2 deletions.
  1. +0 −2 lib/action_controller/parameters.rb
  2. +8 −0 test/nested_parameters_test.rb
View
2 lib/action_controller/parameters.rb
@@ -41,8 +41,6 @@ def permit(*filters)
params[filter] = self[filter] if has_key?(filter)
when Hash then
self.slice(*filter.keys).each do |key, value|
- return unless value
-
key = key.to_sym
params[key] = each_element(value) do |value|
View
8 test/nested_parameters_test.rb
@@ -77,4 +77,12 @@ class NestedParametersTest < ActiveSupport::TestCase
permitted = params.permit book: { genre: :type }
assert_nil permitted[:book][:genre]
end
+
+ test "nil param value that should be a hash" do
+ params = ActionController::Parameters.new({
+ book: nil
+ })
+ permitted = params.permit book: { genre: :type}
+ assert_nil permitted[:book]
+ end
end

0 comments on commit 7e9c635

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