From 1555ae9be1a74a869e4b238e00b820799dab8218 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 18 Sep 2015 11:34:54 -0700 Subject: only wrap the strategy with exception handling we need to be more specific about exception handling when dealing with the parse strategies. The calls to `return yield` can also raise an exception, but we don't want to handle that in *this* code. --- actionpack/lib/action_dispatch/http/request.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'actionpack/lib/action_dispatch/http/request.rb') diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index 148ab7c3b8..ea083425ba 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -353,6 +353,9 @@ module ActionDispatch end self.request_parameters = Request::Utils.normalize_encode_params(pr) end + rescue ParamsParser::ParseError # one of the parse strategies blew up + self.request_parameters = Request::Utils.normalize_encode_params(super || {}) + raise rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e raise ActionController::BadRequest.new(:request, e) end @@ -402,16 +405,14 @@ module ActionDispatch strategy = parsers.fetch(request.content_mime_type) { return yield } - strategy.call(request.raw_post) - - rescue Rack::QueryParser::InvalidParameterError - raise - rescue => e # JSON or Ruby code block errors - my_logger = logger || ActiveSupport::Logger.new($stderr) - my_logger.debug "Error occurred while parsing request parameters.\nContents:\n\n#{request.raw_post}" - request.request_parameters = {} + begin + strategy.call(request.raw_post) + rescue => e # JSON or Ruby code block errors + my_logger = logger || ActiveSupport::Logger.new($stderr) + my_logger.debug "Error occurred while parsing request parameters.\nContents:\n\n#{request.raw_post}" - raise ParamsParser::ParseError.new(e.message, e) + raise ParamsParser::ParseError.new(e.message, e) + end end end end -- cgit v1.2.3