mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Strong parameters should permit nested number as key. Closes #12293
This commit is contained in:
parent
3f488d4a07
commit
277918e61a
3 changed files with 26 additions and 1 deletions
|
@ -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 @@ module ActionController
|
|||
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 @@ module ActionController
|
|||
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 @@ class NestedParametersTest < ActiveSupport::TestCase
|
|||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue