Skip to content

Commit

Permalink
Rework Multipart error classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jan 12, 2023
1 parent 50c85d7 commit 5878656
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/rack/multipart/parser.rb
Expand Up @@ -7,7 +7,8 @@

module Rack
module Multipart
class MultipartPartLimitError < Errno::EMFILE;
class MultipartPartLimitError < Errno::EMFILE
include BadRequest
end

# Use specific error class when parsing multipart request
Expand All @@ -18,9 +19,13 @@ class EmptyContentError < ::EOFError

# Base class for multipart exceptions that do not subclass from
# other exception classes for backwards compatibility.
class Error < StandardError
class BoundaryTooLongError < StandardError
include BadRequest
end

Error = BoundaryTooLongError
deprecate_constant :Error

EOL = "\r\n"
MULTIPART = %r|\Amultipart/.*boundary=\"?([^\";,]+)\"?|ni
TOKEN = /[^\s()<>,;:\\"\/\[\]?=]+/
Expand Down Expand Up @@ -101,7 +106,7 @@ def self.parse(io, content_length, content_type, tmpfile, bufsize, qp)
if boundary.length > 70
# RFC 1521 Section 7.2.1 imposes a 70 character maximum for the boundary.
# Most clients use no more than 55 characters.
raise Error, "multipart boundary size too large (#{boundary.length} characters)"
raise BoundaryTooLongError, "multipart boundary size too large (#{boundary.length} characters)"
end

io = BoundedIO.new(io, content_length) if content_length
Expand Down

0 comments on commit 5878656

Please sign in to comment.