Commit db16bca1 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

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

R=rsc, adg
CC=golang-dev
https://golang.org/cl/4430074
parent 366986a3
......@@ -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 == "" {
......
......@@ -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 {
......
......@@ -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)
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment