mirror of
https://github.com/golang/go
synced 2024-11-21 22:24:40 -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:
parent
849b54a2f9
commit
31fa584906
@ -729,6 +729,9 @@ func (r *Request) ParseForm() (err os.Error) {
|
||||
// ParseMultipartForm calls ParseForm if necessary.
|
||||
// After one call to ParseMultipartForm, subsequent calls have no effect.
|
||||
func (r *Request) ParseMultipartForm(maxMemory int64) os.Error {
|
||||
if r.MultipartForm == multipartByReader {
|
||||
return os.NewError("http: multipart handled by MultipartReader")
|
||||
}
|
||||
if r.Form == nil {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
@ -738,9 +741,6 @@ func (r *Request) ParseMultipartForm(maxMemory int64) os.Error {
|
||||
if r.MultipartForm != nil {
|
||||
return nil
|
||||
}
|
||||
if r.MultipartForm == multipartByReader {
|
||||
return os.NewError("http: multipart handled by MultipartReader")
|
||||
}
|
||||
|
||||
mr, err := r.multipartReader()
|
||||
if err == ErrNotMultipart {
|
||||
|
@ -219,6 +219,18 @@ func TestEmptyMultipartRequest(t *testing.T) {
|
||||
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) {
|
||||
f, fh, err := req.FormFile("missing")
|
||||
if f != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user