diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 92887ed1..6ced0a6d 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -78,6 +78,8 @@ module Sinatra super rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e raise BadRequest, "Invalid query parameters: #{Rack::Utils.escape_html(e.message)}" + rescue EOFError => e + raise BadRequest, "Invalid multipart/form-data: #{Rack::Utils.escape_html(e.message)}" end class AcceptEntry diff --git a/test/request_test.rb b/test/request_test.rb index f4ba50a2..978fe66a 100644 --- a/test/request_test.rb +++ b/test/request_test.rb @@ -17,6 +17,15 @@ class RequestTest < Minitest::Test assert_equal 'bar', request.params['foo'] end + it 'raises Sinatra::BadRequest when multipart/form-data request has no content' do + request = Sinatra::Request.new( + 'REQUEST_METHOD' => 'POST', + 'CONTENT_TYPE' => 'multipart/form-data; boundary=dummy', + 'rack.input' => StringIO.new('') + ) + assert_raises(Sinatra::BadRequest) { request.params } + end + it 'is secure when the url scheme is https' do request = Sinatra::Request.new('rack.url_scheme' => 'https') assert request.secure?