Skip to content

Commit

Permalink
Fix handling of ParseError in controllers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rafaelfranca committed Mar 24, 2021
1 parent bcf3752 commit 7d2d00a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions actionpack/lib/action_controller/metal/params_wrapper.rb
Expand Up @@ -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
Expand All @@ -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
2 changes: 2 additions & 0 deletions actionpack/test/controller/rescue_test.rb
Expand Up @@ -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.

Expand Down

0 comments on commit 7d2d00a

Please sign in to comment.