From 75eaefcc2f7c7526be389702c4802a73d4d934e9 Mon Sep 17 00:00:00 2001 From: Yuki Nishijima Date: Sat, 13 Sep 2014 16:54:20 -0700 Subject: [PATCH] Rescue Rack::Utils::ParameterTypeError instead of TypeError As of rack/rack@167b6480235ff00ed5f355698bf00ec2f250f72e, Rack raises Rack::Utils::ParameterTypeError which inherits TypeError. In terms of the behavior, Rescuing TypeError still works but this method shouldn't rescue if TypeError is raised for other reasons. --- actionpack/lib/action_dispatch/http/request.rb | 4 ++-- actionpack/test/dispatch/request_test.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index c441f7f95b..e854dd266c 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -298,7 +298,7 @@ module ActionDispatch # Override Rack's GET method to support indifferent access def GET @env["action_dispatch.request.query_parameters"] ||= Utils.deep_munge(normalize_encode_params(super || {})) - rescue TypeError, Rack::Utils::InvalidParameterError => e + rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e raise ActionController::BadRequest.new(:query, e) end alias :query_parameters :GET @@ -306,7 +306,7 @@ module ActionDispatch # Override Rack's POST method to support indifferent access def POST @env["action_dispatch.request.request_parameters"] ||= Utils.deep_munge(normalize_encode_params(super || {})) - rescue TypeError, Rack::Utils::InvalidParameterError => e + rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e raise ActionController::BadRequest.new(:request, e) end alias :request_parameters :POST diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index 00b80c7357..a58306ea0a 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -915,7 +915,7 @@ class RequestParameters < BaseRequestTest 2.times do assert_raises(ActionController::BadRequest) do - # rack will raise a TypeError when parsing this query string + # rack will raise a Rack::Utils::ParameterTypeError when parsing this query string request.parameters end end @@ -941,7 +941,7 @@ class RequestParameters < BaseRequestTest ) assert_raises(ActionController::BadRequest) do - # rack will raise a TypeError when parsing this query string + # rack will raise a Rack::Utils::ParameterTypeError when parsing this query string request.parameters end end @@ -950,7 +950,7 @@ class RequestParameters < BaseRequestTest request = stub_request("QUERY_STRING" => "x[y]=1&x[y][][w]=2") e = assert_raises(ActionController::BadRequest) do - # rack will raise a TypeError when parsing this query string + # rack will raise a Rack::Utils::ParameterTypeError when parsing this query string request.parameters end