Permalink
Browse files

Merge pull request #12354 from kennyj/fix_12293

Closes #12293. Strong parameters should permit nested number as key.
  • Loading branch information...
2 parents 4b89734 + 277918e commit 37c721aa8334ba5a6398c6c323c32d6e6c781fe7 @rafaelfranca rafaelfranca committed Sep 29, 2013
@@ -1,3 +1,9 @@
+* Strong parameters should permit nested number as key.
+
+ Fixes #12293
+
+ *kennyj*
+
* Fix regex used to detect URI schemes in `redirect_to` to be consistent with
RFC 3986.
@@ -334,7 +334,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
@@ -343,6 +343,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 37c721a

Please sign in to comment.