Cop idea: Disallow params.require.permit
and params.require
in favor of params.expect
for rails 8.0
#1358
Labels
feature request
Request for new functionality
Is your feature request related to a problem? Please describe.
Rails added
params.expect
in rails/rails#51674. There are some problems withrequire
that are nicely explained in that PR (and linked issues) but it basically boils down to this:params.require(:user).permit(:name)
raises if params looks likeuser=123
(not the expected shape). The newly addedexpect
avoids this problem by making the shape part of the contract.Describe the solution you'd like
Method docs: https://edgeapi.rubyonrails.org/classes/ActionController/Parameters.html#method-i-expect
These two method calls will likely be close together, so I believe it would be best for the cop to simply catch these simple cases first.
Additional context
If plain
params.require
is added as an offense, it must be unsafe. Consider the following case:There is no replacement for the following (yet?):
The text was updated successfully, but these errors were encountered: