aboutsummaryrefslogtreecommitdiff
path: root/src/mime
diff options
context:
space:
mode:
authorNils Larsgård <nilsmagnus@gmail.com>2017-10-24 19:21:58 +0200
committerIan Lance Taylor <iant@golang.org>2017-10-24 20:21:03 +0000
commit81ec7256072ed5e20b8827c583193258769aebc0 (patch)
tree4bc34d2ff61ea6f0a7d605f742ddf6596288289f /src/mime
parent3b9d947b2f4eb3bf7ff01eb33cd1e91bbce73c77 (diff)
downloadgo-81ec7256072ed5e20b8827c583193258769aebc0.tar.gz
go-81ec7256072ed5e20b8827c583193258769aebc0.zip
mime/multipart: permit empty file name
Fixes #19183 Change-Id: I11502d855f5b521b03ed7a63a990cca2d0ed4083 Reviewed-on: https://go-review.googlesource.com/70931 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/mime')
-rw-r--r--src/mime/multipart/formdata.go3
-rw-r--r--src/mime/multipart/formdata_test.go26
2 files changed, 28 insertions, 1 deletions
diff --git a/src/mime/multipart/formdata.go b/src/mime/multipart/formdata.go
index 832d0ad693..2a4ebdd4a0 100644
--- a/src/mime/multipart/formdata.go
+++ b/src/mime/multipart/formdata.go
@@ -58,7 +58,8 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) {
var b bytes.Buffer
- if filename == "" {
+ _, hasContentTypeHeader := p.Header["Content-Type"]
+ if !hasContentTypeHeader && 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 979ae5c4e1..69333d3d0d 100644
--- a/src/mime/multipart/formdata_test.go
+++ b/src/mime/multipart/formdata_test.go
@@ -38,6 +38,23 @@ func TestReadForm(t *testing.T) {
fd.Close()
}
+func TestReadFormWithNamelessFile(t *testing.T) {
+ b := strings.NewReader(strings.Replace(messageWithFileWithoutName, "\n", "\r\n", -1))
+ r := NewReader(b, boundary)
+ f, err := r.ReadForm(25)
+ if err != nil {
+ t.Fatal("ReadForm:", err)
+ }
+ 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)
+ }
+ fd.Close()
+
+}
+
func testFile(t *testing.T, fh *FileHeader, efn, econtent string) File {
if fh.Filename != efn {
t.Errorf("filename = %q, want %q", fh.Filename, efn)
@@ -68,6 +85,15 @@ const (
boundary = `MyBoundary`
)
+const messageWithFileWithoutName = `
+--MyBoundary
+Content-Disposition: form-data; name="hiddenfile"; filename=""
+Content-Type: text/plain
+
+` + filebContents + `
+--MyBoundary--
+`
+
const message = `
--MyBoundary
Content-Disposition: form-data; name="filea"; filename="filea.txt"