lib/rack/multipart/parser.rb in rack-1.4.1 vs lib/rack/multipart/parser.rb in rack-1.4.2
- old
+ new
@@ -46,17 +46,19 @@
@boundary = "--#{$1}"
@buf = ""
@params = Utils::KeySpaceConstrainedParams.new
- @content_length = @env['CONTENT_LENGTH'].to_i
@io = @env['rack.input']
@io.rewind
@boundary_size = Utils.bytesize(@boundary) + EOL.size
- @content_length -= @boundary_size
+ if @content_length = @env['CONTENT_LENGTH']
+ @content_length = @content_length.to_i
+ @content_length -= @boundary_size
+ end
true
end
def full_boundary
@boundary + EOL
@@ -102,14 +104,14 @@
# Save the read body part.
if head && (@boundary_size+4 < @buf.size)
body << @buf.slice!(0, @buf.size - (@boundary_size+4))
end
- content = @io.read(BUFSIZE < @content_length ? BUFSIZE : @content_length)
+ content = @io.read(@content_length && BUFSIZE >= @content_length ? @content_length : BUFSIZE)
raise EOFError, "bad content body" if content.nil? || content.empty?
@buf << content
- @content_length -= content.size
+ @content_length -= content.size if @content_length
end
[head, filename, content_type, name, body]
end