Merge pull request #1351 from jkowens/fix-1350

Fix issue with custom error handler on bad request
This commit is contained in:
namusyaka 2018-02-07 02:35:39 +09:00 committed by GitHub
commit d661739853
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -915,6 +915,7 @@ module Sinatra
def call!(env) # :nodoc: def call!(env) # :nodoc:
@env = env @env = env
@params = IndifferentHash.new
@request = Request.new(env) @request = Request.new(env)
@response = Response.new @response = Response.new
template_cache.clear if settings.reload_templates template_cache.clear if settings.reload_templates
@ -1087,7 +1088,7 @@ module Sinatra
# Dispatch a request with error handling. # Dispatch a request with error handling.
def dispatch! def dispatch!
force_encoding(@params = IndifferentHash[@request.params]) force_encoding(@params.merge!(@request.params))
invoke do invoke do
static! if settings.static? && (request.get? || request.head?) static! if settings.static? && (request.get? || request.head?)

View File

@ -201,6 +201,21 @@ class RoutingTest < Minitest::Test
assert_equal "This is not a drill either", response.body assert_equal "This is not a drill either", response.body
end 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 it "uses 404 error handler for not matching route" do
mock_app { mock_app {
not_found do not_found do