diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 688bcc39..b2dff314 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -915,6 +915,7 @@ module Sinatra def call!(env) # :nodoc: @env = env + @params = IndifferentHash.new @request = Request.new(env) @response = Response.new template_cache.clear if settings.reload_templates @@ -1087,7 +1088,7 @@ module Sinatra # Dispatch a request with error handling. def dispatch! - force_encoding(@params = IndifferentHash[@request.params]) + force_encoding(@params.merge!(@request.params)) invoke do static! if settings.static? && (request.get? || request.head?) diff --git a/test/routing_test.rb b/test/routing_test.rb index de6cfef4..621b78e3 100644 --- a/test/routing_test.rb +++ b/test/routing_test.rb @@ -201,6 +201,21 @@ class RoutingTest < Minitest::Test assert_equal "This is not a drill either", response.body end + it "captures the custom exception message of a BadRequest" do + mock_app { + get('/') {} + + error Sinatra::BadRequest do + 'This is not a drill either' + end + } + + get "/", "foo" => "", "foo[]" => "" + assert_equal "26", response["Content-Length"] + assert_equal 400, status + assert_equal "This is not a drill either", response.body + end + it "uses 404 error handler for not matching route" do mock_app { not_found do