Permalink
Browse files

Merge pull request #12354 from kennyj/fix_12293

Closes #12293. Strong parameters should permit nested number as key.
Conflicts:
	actionpack/CHANGELOG.md
  • Loading branch information...
1 parent d62a95a commit d663c190d9a7739651f80e4941669e69d196a613 @rafaelfranca rafaelfranca committed Sep 29, 2013
View
@@ -1,5 +1,11 @@
## unreleased ##
+* Strong parameters should permit nested number as key.
+
+ Fixes #12293
+
+ *kennyj*
+
* Fix `collection_check_boxes` generated hidden input to use the name attribute provided
in the options hash.
@@ -329,7 +329,7 @@ def convert_hashes_to_parameters(key, value)
def each_element(object)
if object.is_a?(Array)
object.map { |el| yield el }.compact
- elsif object.is_a?(Hash) && object.keys.all? { |k| k =~ /\A-?\d+\z/ }
+ elsif fields_for_style?(object)
hash = object.class.new
object.each { |k,v| hash[k] = yield v }
hash
@@ -338,6 +338,10 @@ def each_element(object)
end
end
+ def fields_for_style?(object)
+ object.is_a?(Hash) && object.all? { |k, v| k =~ /\A-?\d+\z/ && v.is_a?(Hash) }
+ end
+
def unpermitted_parameters!(params)
unpermitted_keys = unpermitted_keys(params)
if unpermitted_keys.any?
@@ -169,4 +169,19 @@ def assert_filtered_out(params, key)
assert_filtered_out permitted[:book][:authors_attributes]['-1'], :age_of_death
end
+
+ test "nested number as key" do
+ params = ActionController::Parameters.new({
+ product: {
+ properties: {
+ '0' => "prop0",
+ '1' => "prop1"
+ }
+ }
+ })
+ params = params.require(:product).permit(:properties => ["0"])
+ assert_not_nil params[:properties]["0"]
+ assert_nil params[:properties]["1"]
+ assert_equal "prop0", params[:properties]["0"]
+ end
end

0 comments on commit d663c19

Please sign in to comment.