Commit 46076c37 authored by Constantin Konstantinidis's avatar Constantin Konstantinidis Committed by Brad Fitzpatrick

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/118822Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
parent 90559ab9
......@@ -313,7 +313,9 @@ func (r *Reader) NextPart() (*Part, error) {
if r.currentPart != nil {
r.currentPart.Close()
}
if string(r.dashBoundary) == "--" {
return nil, fmt.Errorf("multipart: boundary is empty")
}
expectNewPart := false
for {
line, err := r.bufReader.ReadSlice('\n')
......
......@@ -880,3 +880,11 @@ func roundTripParseTest() parseTest {
t.sep = w.Boundary()
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)
}
}
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