diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f024e744..858c37a13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. For info on - Removed antiquated handlers: FCGI, LSWS, SCGI, Thin. ([#1658](https://github.com/rack/rack/pull/1658), [@ioquatix](https://github.com/ioquatix)) - Removed options from `Rack::Builder.parse_file` and `Rack::Builder.load_file`. ([#1663](https://github.com/rack/rack/pull/1663), [@ioquatix](https://github.com/ioquatix)) - HMAC argument for `Rack::Session::Cookie` doesn't accept a class constant anymore, but only a string recognized by OpenSSL (e.g. `"SHA256"`) or compatible instance (e.g. `OpenSSL::Digest.new("SHA256")`) ([#1676](https://github.com/rack/rack/pull/1676), [@bdewater](https://github.com/bdewater)) +- 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 diff --git a/lib/rack/multipart/parser.rb b/lib/rack/multipart/parser.rb index 19e34029a..061647319 100644 --- a/lib/rack/multipart/parser.rb +++ b/lib/rack/multipart/parser.rb @@ -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' @@ -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 diff --git a/test/spec_multipart.rb b/test/spec_multipart.rb index 717e0dc81..23b8493d4 100644 --- a/test/spec_multipart.rb +++ b/test/spec_multipart.rb @@ -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