You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current documentation for Rails/StrongParametersExpect says that it's unsafe because the response code on invalid parameters changes from 500 to 400.
As a matter of fact, I do not think this check should be auto-corrected. A manual decision is always necessary in this common case:
params.require(:foo).permit(bar: [:baz])
If the key :bar contains a single object/hash, Rubocop is correctly changing this to:
params.expect(foo: {bar: [:baz]})
But if :bar contains an array, it should be changed to this instead:
params.expect(foo: {bar: [[:baz]]})
I don't think that Rubocop can tell automatically which one is the case.
It is also quite common for issues introduced by this auto fix to silently fail, and even pass specs if the specs do not explicitly make use of the inner array.
The current documentation for
Rails/StrongParametersExpect
says that it's unsafe because the response code on invalid parameters changes from 500 to 400.rubocop-rails/lib/rubocop/cop/rails/strong_parameters_expect.rb
Lines 8 to 12 in 1c4c37e
But it's also unsafe because
ActionController::Parameters#expect
is pickier about the format and may change some successful requests into failures.https://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-expect
This should be documented in the cop.
Example
The cop turned this code:
into this (after correction for #1417):
which now fails on these request parameters:
The problem seems to be the lack of double array brackets on the value for
comments_attributes
. Corrected code:(The extra array also works with
#require
/#permit
.)Rubocop version
The text was updated successfully, but these errors were encountered: