Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise Rack::Multipart::EmptyContentError instead of EOFError for parsing empty body #1688

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file. For info on
- `Rack::HTTP_VERSION` has been removed and the `HTTP_VERSION` env setting is no longer set in the CGI and Webrick handlers . ([#970](https://github.com/rack/rack/issues/970), [@jeremyevans](https://github.com/jeremyevans))
- `Rack::Request#[]` and `#[]=` now warn even in non-verbose mode. ([#1277](https://github.com/rack/rack/issues/1277), [@jeremyevans](https://github.com/jeremyevans))
- Decrease default allowed parameter recursion level from 100 to 32. ([#1640](https://github.com/rack/rack/issues/1640), [@jeremyevans](https://github.com/jeremyevans))
- Attempting to parse a multipart response with an empty body now raises Rack::Multipart::EmptyContentError. ([#1603](https://github.com/rack/rack/issues/1603), [@jeremyevans](https://github.com/jeremyevans))

### Fixed

Expand Down
6 changes: 5 additions & 1 deletion lib/rack/multipart/parser.rb
Expand Up @@ -6,6 +6,10 @@ module Rack
module Multipart
class MultipartPartLimitError < Errno::EMFILE; end

# Use specific error class when parsing multipart request
# that ends early.
class EmptyContentError < ::EOFError; end

class Parser
(require_relative '../core_ext/regexp'; using ::Rack::RegexpExtensions) if RUBY_VERSION < '2.4'

Expand Down Expand Up @@ -356,7 +360,7 @@ def tag_multipart_encoding(filename, content_type, name, body)

def handle_empty_content!(content)
if content.nil? || content.empty?
raise EOFError
raise EmptyContentError
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/spec_multipart.rb
Expand Up @@ -151,7 +151,7 @@ def rd.rewind; end
env = Rack::MockRequest.env_for '/', fixture
lambda {
Rack::Multipart.parse_multipart(env)
}.must_raise EOFError
}.must_raise Rack::Multipart::EmptyContentError
rd.close

err = thr.value
Expand Down