1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:04:39 -07:00

multipart: return an error on Reader EOF, not (nil, nil)

R=rsc, adg
CC=golang-dev
https://golang.org/cl/4430074
This commit is contained in:
Brad Fitzpatrick 2011-05-01 18:23:39 -07:00
parent 366986a3fe
commit db16bca18f
3 changed files with 11 additions and 14 deletions

View File

@ -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 == "" {

View File

@ -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 {

View File

@ -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)
}
}