Skip to content

Commit fd890f6

Browse files
committed
Merge pull request rails#9857 from yyyc514/bad_params_should_400
failure to parse params should trigger a 400 Bad Request
2 parents c68b6f0 + ea2336b commit fd890f6

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

actionpack/lib/action_dispatch/middleware/exception_wrapper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class ExceptionWrapper
1313
'ActionController::NotImplemented' => :not_implemented,
1414
'ActionController::UnknownFormat' => :not_acceptable,
1515
'ActionController::InvalidAuthenticityToken' => :unprocessable_entity,
16+
'ActionDispatch::ParamsParser::ParseError' => :bad_request,
1617
'ActionController::BadRequest' => :bad_request,
1718
'ActionController::ParameterMissing' => :bad_request
1819
)

actionpack/test/dispatch/show_exceptions_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ def call(env)
88
case req.path
99
when "/not_found"
1010
raise AbstractController::ActionNotFound
11+
when "/bad_params"
12+
raise ActionDispatch::ParamsParser::ParseError.new("", StandardError.new)
1113
when "/method_not_allowed"
1214
raise ActionController::MethodNotAllowed
1315
when "/unknown_http_method"
@@ -35,6 +37,10 @@ def call(env)
3537
get "/", {}, {'action_dispatch.show_exceptions' => true}
3638
assert_response 500
3739
assert_equal "500 error fixture\n", body
40+
41+
get "/bad_params", {}, {'action_dispatch.show_exceptions' => true}
42+
assert_response 400
43+
assert_equal "400 error fixture\n", body
3844

3945
get "/not_found", {}, {'action_dispatch.show_exceptions' => true}
4046
assert_response 404
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
400 error fixture

0 commit comments

Comments
 (0)