1
0
mirror of https://github.com/golang/go synced 2024-11-25 08:57:58 -07:00

http: fix ParseMultipartForm after MultipartReader error

Addresses part of issue 2093
Thanks to espians....@

R=golang-dev, nigeltao
CC=golang-dev
https://golang.org/cl/4808087
This commit is contained in:
Brad Fitzpatrick 2011-08-10 08:08:53 -07:00
parent 849b54a2f9
commit 31fa584906
2 changed files with 15 additions and 3 deletions

View File

@ -729,6 +729,9 @@ func (r *Request) ParseForm() (err os.Error) {
// ParseMultipartForm calls ParseForm if necessary. // ParseMultipartForm calls ParseForm if necessary.
// After one call to ParseMultipartForm, subsequent calls have no effect. // After one call to ParseMultipartForm, subsequent calls have no effect.
func (r *Request) ParseMultipartForm(maxMemory int64) os.Error { func (r *Request) ParseMultipartForm(maxMemory int64) os.Error {
if r.MultipartForm == multipartByReader {
return os.NewError("http: multipart handled by MultipartReader")
}
if r.Form == nil { if r.Form == nil {
err := r.ParseForm() err := r.ParseForm()
if err != nil { if err != nil {
@ -738,9 +741,6 @@ func (r *Request) ParseMultipartForm(maxMemory int64) os.Error {
if r.MultipartForm != nil { if r.MultipartForm != nil {
return nil return nil
} }
if r.MultipartForm == multipartByReader {
return os.NewError("http: multipart handled by MultipartReader")
}
mr, err := r.multipartReader() mr, err := r.multipartReader()
if err == ErrNotMultipart { if err == ErrNotMultipart {

View File

@ -219,6 +219,18 @@ func TestEmptyMultipartRequest(t *testing.T) {
testMissingFile(t, req) testMissingFile(t, req)
} }
func TestRequestMultipartCallOrder(t *testing.T) {
req := newTestMultipartRequest(t)
_, err := req.MultipartReader()
if err != nil {
t.Fatalf("MultipartReader: %v", err)
}
err = req.ParseMultipartForm(1024)
if err == nil {
t.Errorf("expected an error from ParseMultipartForm after call to MultipartReader")
}
}
func testMissingFile(t *testing.T, req *Request) { func testMissingFile(t *testing.T, req *Request) {
f, fh, err := req.FormFile("missing") f, fh, err := req.FormFile("missing")
if f != nil { if f != nil {