1
0
mirror of https://github.com/golang/go synced 2024-10-01 13:28:37 -06:00

mime/multipart: return error from NextPart if boundary is empty

NewReader cannot return an error. This behaviour is kept.
NextPart returns EOF when boundary is empty.
RFC 2046 does not allow it. The fix is to return an error
on the call of NextPart.

Fixes #23170

Change-Id: I775afd3f93e8b56e6cb274bc5c9de362a18bcc3c
Reviewed-on: https://go-review.googlesource.com/118822
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Constantin Konstantinidis 2018-06-14 11:51:57 +02:00 committed by Brad Fitzpatrick
parent 90559ab9f2
commit 46076c3757
2 changed files with 11 additions and 1 deletions

View File

@ -313,7 +313,9 @@ func (r *Reader) NextPart() (*Part, error) {
if r.currentPart != nil { if r.currentPart != nil {
r.currentPart.Close() r.currentPart.Close()
} }
if string(r.dashBoundary) == "--" {
return nil, fmt.Errorf("multipart: boundary is empty")
}
expectNewPart := false expectNewPart := false
for { for {
line, err := r.bufReader.ReadSlice('\n') line, err := r.bufReader.ReadSlice('\n')

View File

@ -880,3 +880,11 @@ func roundTripParseTest() parseTest {
t.sep = w.Boundary() t.sep = w.Boundary()
return t return t
} }
func TestNoBoundary(t *testing.T) {
mr := NewReader(strings.NewReader(""), "")
_, err := mr.NextPart()
if got, want := fmt.Sprint(err), "multipart: boundary is empty"; got != want {
t.Errorf("NextPart error = %v; want %v", got, want)
}
}