Fix handling of ParseError in controllers

It regressed in #34894, which moved the rescue to the wrong method.
`_wrapper_enabled?` can access the parameters and the exception will
raise there before even entering `_perfomr_parameter_wrapping`.

Closes #38285.
This commit is contained in:
Rafael Mendonça França 2021-03-24 22:53:27 +00:00
parent bcf3752247
commit 7d2d00a334
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
2 changed files with 5 additions and 2 deletions

@ -281,7 +281,10 @@ def _wrapper_enabled?
return false unless request.has_content_type?
ref = request.content_mime_type.ref
_wrapper_formats.include?(ref) && _wrapper_key && !request.parameters.key?(_wrapper_key)
rescue ActionDispatch::Http::Parameters::ParseError
false
end
def _perform_parameter_wrapping
@ -295,8 +298,6 @@ def _perform_parameter_wrapping
# This will display the wrapped hash in the log file.
request.filtered_parameters.merge! wrapped_filtered_hash
rescue ActionDispatch::Http::Parameters::ParseError
# swallow parse error exception
end
end
end

@ -33,6 +33,8 @@ class ResourceUnavailable < StandardError
class ResourceUnavailableToRescueAsString < StandardError
end
wrap_parameters format: :json
# We use a fully qualified name in some strings, and a relative constant
# name in some other to test correct handling of both cases.