diff --git a/pkg/util/multipart/reader.go b/pkg/util/multipart/reader.go index 2a591ce716..9f3c4d61dc 100644 --- a/pkg/util/multipart/reader.go +++ b/pkg/util/multipart/reader.go @@ -1,13 +1,13 @@ package multipart import ( - "io" + "bytes" "crypto/rand" "fmt" + "io" "net/textproto" - "strings" - "bytes" "sort" + "strings" ) type SReader struct { @@ -88,12 +88,10 @@ func (r *SReader) Read(p []byte) (n int, err error) { if read < len(p) && !r.bodyEof { n, err := r.body.Read(p[read:]) read += n - if err != nil { - if err == io.EOF { - r.bodyEof = true - } else { - return read, err - } + if err == io.EOF || n == 0 { + r.bodyEof = true + } else { + return read, err } } for read < len(p) && r.tailOffset < len(r.tail) { diff --git a/pkg/util/multipart/reader_test.go b/pkg/util/multipart/reader_test.go index 118d643461..1e54031089 100644 --- a/pkg/util/multipart/reader_test.go +++ b/pkg/util/multipart/reader_test.go @@ -1,10 +1,10 @@ package multipart import ( - "testing" - "strings" "bytes" "io" + "strings" + "testing" ) func TestReader(t *testing.T) {