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

Don't use #eof? when parsing multipart #1201

Merged
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
15 changes: 6 additions & 9 deletions lib/rack/multipart/parser.rb
Expand Up @@ -39,8 +39,6 @@ def read(size)
str
end

def eof?; @content_length == @cursor; end

def rewind
@io.rewind
end
Expand All @@ -65,11 +63,11 @@ def self.parse(io, content_length, content_type, tmpfile, bufsize, qp)
io = BoundedIO.new(io, content_length) if content_length

parser = new(boundary, tmpfile, bufsize, qp)
parser.on_read io.read(bufsize), io.eof?
parser.on_read io.read(bufsize)

loop do
break if parser.state == :DONE
parser.on_read io.read(bufsize), io.eof?
parser.on_read io.read(bufsize)
end

io.rewind
Expand Down Expand Up @@ -181,8 +179,8 @@ def initialize(boundary, tempfile, bufsize, query_parser)
@collector = Collector.new tempfile
end

def on_read content, eof
handle_empty_content!(content, eof)
def on_read content
handle_empty_content!(content)
@buf << content
run_parser
end
Expand Down Expand Up @@ -358,10 +356,9 @@ def tag_multipart_encoding(filename, content_type, name, body)
end


def handle_empty_content!(content, eof)
def handle_empty_content!(content)
if content.nil? || content.empty?
raise EOFError if eof
return true
raise EOFError
end
end
end
Expand Down