Skip to content

Commit

Permalink
Handle EOFError raised by Rack
Browse files Browse the repository at this point in the history
  • Loading branch information
tamazon committed Jan 30, 2022
1 parent e69b6b9 commit df65a73
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/sinatra/base.rb
Expand Up @@ -78,6 +78,8 @@ def params
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
Expand Down
9 changes: 9 additions & 0 deletions test/request_test.rb
Expand Up @@ -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?
Expand Down

0 comments on commit df65a73

Please sign in to comment.