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>
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 {
}
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) {
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