aboutsummaryrefslogtreecommitdiff
path: root/src/mime
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2018-06-26 15:57:35 -0700
committerIan Lance Taylor <iant@golang.org>2018-06-26 23:56:13 +0000
commitf040e439cbf860244d2bd9d6808712b93c31c605 (patch)
treec1f4572a6f11bac0d384a2e41bd6afa486ab8cdc /src/mime
parent0436b162397018c45068b47ca1b5924a3eafdee0 (diff)
downloadgo-f040e439cbf860244d2bd9d6808712b93c31c605.tar.gz
go-f040e439cbf860244d2bd9d6808712b93c31c605.zip
mime/multipart: restore 1.9 handling of missing/empty form-data file name
Revert the code changes of CL 96975 and CL 70931, but keep the tests, appropriately modified for the code changes. This restores the 1.9 handling of form-data entries with missing or empty file names. Changing the handling of this simply confused existing programs for no useful benefit. Go back to the old behavior. Updates #19183 Fixes #24041 Change-Id: I4ebc32433911e6360b9fd79d8f63a6d884822e0e Reviewed-on: https://go-review.googlesource.com/121055 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/mime')
-rw-r--r--src/mime/multipart/formdata.go2
-rw-r--r--src/mime/multipart/formdata_test.go7
-rw-r--r--src/mime/multipart/multipart.go10
3 files changed, 3 insertions, 16 deletions
diff --git a/src/mime/multipart/formdata.go b/src/mime/multipart/formdata.go
index 22e2c8d323..832d0ad693 100644
--- a/src/mime/multipart/formdata.go
+++ b/src/mime/multipart/formdata.go
@@ -58,7 +58,7 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) {
var b bytes.Buffer
- if !p.hasFileName() {
+ if filename == "" {
// value, store as string in memory
n, err := io.CopyN(&b, p, maxValueBytes+1)
if err != nil && err != io.EOF {
diff --git a/src/mime/multipart/formdata_test.go b/src/mime/multipart/formdata_test.go
index 5e3c3330f3..2d6a830cb6 100644
--- a/src/mime/multipart/formdata_test.go
+++ b/src/mime/multipart/formdata_test.go
@@ -47,12 +47,9 @@ func TestReadFormWithNamelessFile(t *testing.T) {
}
defer f.RemoveAll()
- fd := testFile(t, f.File["hiddenfile"][0], "", filebContents)
- if _, ok := fd.(sectionReadCloser); !ok {
- t.Errorf("file has unexpected underlying type %T", fd)
+ if g, e := f.Value["hiddenfile"][0], filebContents; g != e {
+ t.Errorf("hiddenfile value = %q, want %q", g, e)
}
- fd.Close()
-
}
func TestReadFormWithTextContentType(t *testing.T) {
diff --git a/src/mime/multipart/multipart.go b/src/mime/multipart/multipart.go
index b1b78ecb9a..0993fb7e91 100644
--- a/src/mime/multipart/multipart.go
+++ b/src/mime/multipart/multipart.go
@@ -81,16 +81,6 @@ func (p *Part) FileName() string {
return p.dispositionParams["filename"]
}
-// hasFileName determines if a (empty or otherwise)
-// filename parameter was included in the Content-Disposition header
-func (p *Part) hasFileName() bool {
- if p.dispositionParams == nil {
- p.parseContentDisposition()
- }
- _, ok := p.dispositionParams["filename"]
- return ok
-}
-
func (p *Part) parseContentDisposition() {
v := p.Header.Get("Content-Disposition")
var err error