Skip to content

Commit

Permalink
Merge pull request #1743 from tamazon/fix_EOFError
Browse files Browse the repository at this point in the history
Handle EOFError raised by Rack and raise BadRequest (and lock Rack version to 2.0 to pass tests)
  • Loading branch information
jkowens committed Feb 2, 2022
2 parents 59d8b26 + c29749d commit f6cee1c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -11,7 +11,7 @@ source 'https://rubygems.org' unless ENV['QUICK']
gemspec

gem 'rake'
gem 'rack', git: 'https://github.com/rack/rack.git'
gem 'rack', '~> 2.0'
gem 'rack-test', '>= 0.6.2'
gem "minitest", "~> 5.0"
gem 'yard'
Expand Down
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 f6cee1c

Please sign in to comment.