From 9d1afbf308f2ac382f364f935867ce0cef0a3573 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Thu, 11 May 2023 15:23:39 +0700 Subject: mime/multipart: fix ReadForm always return (nil,io.EOF) Previously, the condition err == io.EOF in readForm will never true and break; it always goes to the second condition, err != nil, which cause the returned ReadForm always nil with err is io.EOF. As the test, we use the example with body almost similar to ExampleNewReader with header contains "Content-Disposition:form-data". Change-Id: I7268f45bb26eafb7f1e6e471b86eec681dde99f7 --- src/net/http/request_test.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/net') diff --git a/src/net/http/request_test.go b/src/net/http/request_test.go index 78b968f23c..c952b0ad26 100644 --- a/src/net/http/request_test.go +++ b/src/net/http/request_test.go @@ -251,14 +251,17 @@ func TestParseMultipartForm(t *testing.T) { Body: io.NopCloser(new(bytes.Buffer)), } err := req.ParseMultipartForm(25) - if err == nil { - t.Error("expected multipart EOF, got nil") + if err != nil { + t.Errorf("expecting nil, got %v", err) } + // Reset to allow the call to multipartReader. + req.MultipartForm = nil + req.Header = Header{"Content-Type": {"text/plain"}} err = req.ParseMultipartForm(25) - if err != ErrNotMultipart { - t.Error("expected ErrNotMultipart for text/plain") + if !errors.Is(err, ErrNotMultipart) { + t.Errorf("expected ErrNotMultipart for text/plain, got %v", err) } } -- cgit v1.3