Skip to content

Commit fe859a5

Browse files
committed
Handle Rack::QueryParser errors in ActionDispatch::ExceptionWrapper
Rack [recently](rack/rack@7e7a389) moved the namespace of its `ParameterTypeError` and `InvalidParameterError` errors. Whilst an alias for the old name was added, the logic in `ActionDispatch::ExceptionWrapper` was still broken by this change, since it relies on the class name. This PR updates `ActionDispatch::ExceptionWrapper` to handle the Rack 2.0 namespaced errors correctly. We no longer need to worry about the old names, since Rails specifies Rack ~> 2.0.
1 parent de1227a commit fe859a5

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

actionpack/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1+
* Handle `Rack::QueryParser` errors in `ActionDispatch::ExceptionWrapper`
2+
3+
Updated `ActionDispatch::ExceptionWrapper` to handle the Rack 2.0 namespace
4+
for `ParameterTypeError` and `InvalidParameterError` errors.
5+
6+
*Grey Baker*
17

28
Please check [5-0-stable](https://github.com/rails/rails/blob/5-0-stable/actionpack/CHANGELOG.md) for previous changes.

actionpack/lib/action_dispatch/middleware/exception_wrapper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class ExceptionWrapper
1717
'ActionDispatch::ParamsParser::ParseError' => :bad_request,
1818
'ActionController::BadRequest' => :bad_request,
1919
'ActionController::ParameterMissing' => :bad_request,
20-
'Rack::Utils::ParameterTypeError' => :bad_request,
21-
'Rack::Utils::InvalidParameterError' => :bad_request
20+
'Rack::QueryParser::ParameterTypeError' => :bad_request,
21+
'Rack::QueryParser::InvalidParameterError' => :bad_request
2222
)
2323

2424
cattr_accessor :rescue_templates

actionpack/test/dispatch/exception_wrapper_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ def backtrace
5757
assert_equal [ "lib/file.rb:42:in `index'" ], wrapper.application_trace
5858
end
5959

60+
test '#status_code returns 400 for Rack::Utils::ParameterTypeError' do
61+
exception = Rack::Utils::ParameterTypeError.new
62+
wrapper = ExceptionWrapper.new(@cleaner, exception)
63+
assert_equal 400, wrapper.status_code
64+
end
65+
6066
test '#application_trace cannot be nil' do
6167
nil_backtrace_wrapper = ExceptionWrapper.new(@cleaner, BadlyDefinedError.new)
6268
nil_cleaner_wrapper = ExceptionWrapper.new(nil, BadlyDefinedError.new)

0 commit comments

Comments
 (0)