1
0
mirror of https://github.com/golang/go synced 2024-11-21 21:44:40 -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. maxValueBytes := int64(10 << 20) // 10 MB is a lot of text.
for { for {
p, err := r.NextPart() p, err := r.NextPart()
if err == os.EOF {
break
}
if err != nil { if err != nil {
return nil, err return nil, err
} }
if p == nil {
break
}
name := p.FormName() name := p.FormName()
if name == "" { 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 // Reader's underlying parser consumes its input as needed. Seeking
// isn't supported. // isn't supported.
type Reader interface { type Reader interface {
// NextPart returns the next part in the multipart, or (nil, // NextPart returns the next part in the multipart or an error.
// nil) on EOF. An error is returned if the underlying reader // When there are no more parts, the error os.EOF is returned.
// reports errors, or on truncated or otherwise malformed
// input.
NextPart() (*Part, os.Error) NextPart() (*Part, os.Error)
// ReadForm parses an entire multipart message whose parts have // 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) { if hasPrefixThenNewline(line, mr.dashBoundaryDash) {
// Expected EOF (no error) // Expected EOF
// TODO(bradfitz): should return an os.EOF error here, not using nil for errors return nil, os.EOF
return nil, nil
} }
if expectNewPart { if expectNewPart {

View File

@ -201,8 +201,8 @@ func testMultipart(t *testing.T, r io.Reader) {
if part != nil { if part != nil {
t.Error("Didn't expect a fifth part.") t.Error("Didn't expect a fifth part.")
} }
if err != nil { if err != os.EOF {
t.Errorf("Unexpected error getting fifth part: %v", err) t.Errorf("On fifth part expected os.EOF; got %v", err)
} }
} }
@ -246,8 +246,8 @@ func TestVariousTextLineEndings(t *testing.T) {
if part != nil { if part != nil {
t.Errorf("Unexpected part in test %d", testNum) t.Errorf("Unexpected part in test %d", testNum)
} }
if err != nil { if err != os.EOF {
t.Errorf("Unexpected error in test %d: %v", testNum, err) t.Errorf("On test %d expected os.EOF; got %v", testNum, err)
} }
} }