From db16bca18f44af824127dbe0bf31e81b97f2ee1b Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 1 May 2011 18:23:39 -0700 Subject: [PATCH] multipart: return an error on Reader EOF, not (nil, nil) R=rsc, adg CC=golang-dev https://golang.org/cl/4430074 --- src/pkg/mime/multipart/formdata.go | 6 +++--- src/pkg/mime/multipart/multipart.go | 11 ++++------- src/pkg/mime/multipart/multipart_test.go | 8 ++++---- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/pkg/mime/multipart/formdata.go b/src/pkg/mime/multipart/formdata.go index 2879385571..198ab515b8 100644 --- a/src/pkg/mime/multipart/formdata.go +++ b/src/pkg/mime/multipart/formdata.go @@ -30,12 +30,12 @@ func (r *multiReader) ReadForm(maxMemory int64) (f *Form, err os.Error) { maxValueBytes := int64(10 << 20) // 10 MB is a lot of text. for { p, err := r.NextPart() + if err == os.EOF { + break + } if err != nil { return nil, err } - if p == nil { - break - } name := p.FormName() if name == "" { diff --git a/src/pkg/mime/multipart/multipart.go b/src/pkg/mime/multipart/multipart.go index 60329fe17b..839a72f9c3 100644 --- a/src/pkg/mime/multipart/multipart.go +++ b/src/pkg/mime/multipart/multipart.go @@ -30,10 +30,8 @@ var headerRegexp *regexp.Regexp = regexp.MustCompile("^([a-zA-Z0-9\\-]+): *([^\r // Reader's underlying parser consumes its input as needed. Seeking // isn't supported. type Reader interface { - // NextPart returns the next part in the multipart, or (nil, - // nil) on EOF. An error is returned if the underlying reader - // reports errors, or on truncated or otherwise malformed - // input. + // NextPart returns the next part in the multipart or an error. + // When there are no more parts, the error os.EOF is returned. NextPart() (*Part, os.Error) // ReadForm parses an entire multipart message whose parts have @@ -207,9 +205,8 @@ func (mr *multiReader) NextPart() (*Part, os.Error) { } if hasPrefixThenNewline(line, mr.dashBoundaryDash) { - // Expected EOF (no error) - // TODO(bradfitz): should return an os.EOF error here, not using nil for errors - return nil, nil + // Expected EOF + return nil, os.EOF } if expectNewPart { diff --git a/src/pkg/mime/multipart/multipart_test.go b/src/pkg/mime/multipart/multipart_test.go index 16249146c9..05f4871472 100644 --- a/src/pkg/mime/multipart/multipart_test.go +++ b/src/pkg/mime/multipart/multipart_test.go @@ -201,8 +201,8 @@ func testMultipart(t *testing.T, r io.Reader) { if part != nil { t.Error("Didn't expect a fifth part.") } - if err != nil { - t.Errorf("Unexpected error getting fifth part: %v", err) + if err != os.EOF { + t.Errorf("On fifth part expected os.EOF; got %v", err) } } @@ -246,8 +246,8 @@ func TestVariousTextLineEndings(t *testing.T) { if part != nil { t.Errorf("Unexpected part in test %d", testNum) } - if err != nil { - t.Errorf("Unexpected error in test %d: %v", testNum, err) + if err != os.EOF { + t.Errorf("On test %d expected os.EOF; got %v", testNum, err) } }