mirror of
https://github.com/golang/go
synced 2024-11-19 05:04:43 -07: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:
parent
90559ab9f2
commit
46076c3757
@ -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')
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user