summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-05-16 11:45:25 +0200
committerOndřej Surý <ondrej@sury.org>2011-05-16 11:45:25 +0200
commitda195b66d4d4df70e6884c8743382a244757cd20 (patch)
tree242e303ae6e8bfdaa9f26ea47159d45a55061217
parent14cda8f405d55947c0a3fae0852b04af8405eae0 (diff)
downloadgolang-da195b66d4d4df70e6884c8743382a244757cd20.tar.gz
Imported Upstream version 57.1upstream/57.1
-rw-r--r--doc/devel/release.html6
-rw-r--r--src/pkg/http/request.go8
-rw-r--r--src/pkg/http/request_test.go28
3 files changed, 38 insertions, 4 deletions
diff --git a/doc/devel/release.html b/doc/devel/release.html
index 4799126ff..8f28945ef 100644
--- a/doc/devel/release.html
+++ b/doc/devel/release.html
@@ -22,7 +22,7 @@ The r57 release corresponds to
with additional bug fixes.
This section highlights the most significant changes in this release.
For a more detailed summary, see the
-The <a href="weekly.html#2011-04-27">weekly release notes</a>.
+<a href="weekly.html#2011-04-27">weekly release notes</a>.
For complete information, see the
<a href="http://code.google.com/p/go/source/list?r=release-branch.r57">Mercurial change list</a>.
</p>
@@ -159,6 +159,10 @@ documentation.
For other uses, see the <a href="/pkg/runtime/pprof/">runtime/pprof</a> documentation.
</p>
+<h3 id="r57.minor">Minor revisions</h3>
+
+<p>r57.1 fixes a <a href="http://code.google.com/p/go/source/detail?r=ff2bc62726e7145eb2ecc1e0f076998e4a8f86f0">nil pointer dereference in http.FormFile</a>.</p>
+
<h2 id="r56">r56 (released 2011/03/16)</h2>
<p>
diff --git a/src/pkg/http/request.go b/src/pkg/http/request.go
index b8e9a2142..4852ca3e1 100644
--- a/src/pkg/http/request.go
+++ b/src/pkg/http/request.go
@@ -715,9 +715,11 @@ func (r *Request) FormFile(key string) (multipart.File, *multipart.FileHeader, o
return nil, nil, err
}
}
- if fhs := r.MultipartForm.File[key]; len(fhs) > 0 {
- f, err := fhs[0].Open()
- return f, fhs[0], err
+ if r.MultipartForm != nil && r.MultipartForm.File != nil {
+ if fhs := r.MultipartForm.File[key]; len(fhs) > 0 {
+ f, err := fhs[0].Open()
+ return f, fhs[0], err
+ }
}
return nil, nil, ErrMissingFile
}
diff --git a/src/pkg/http/request_test.go b/src/pkg/http/request_test.go
index f982471d8..f79d3a242 100644
--- a/src/pkg/http/request_test.go
+++ b/src/pkg/http/request_test.go
@@ -200,6 +200,29 @@ func TestMultipartRequestAuto(t *testing.T) {
validateTestMultipartContents(t, req, true)
}
+func TestEmptyMultipartRequest(t *testing.T) {
+ // Test that FormValue and FormFile automatically invoke
+ // ParseMultipartForm and return the right values.
+ req, err := NewRequest("GET", "/", nil)
+ if err != nil {
+ t.Errorf("NewRequest err = %q", err)
+ }
+ testMissingFile(t, req)
+}
+
+func testMissingFile(t *testing.T, req *Request) {
+ f, fh, err := req.FormFile("missing")
+ if f != nil {
+ t.Errorf("FormFile file = %q, want nil", f, nil)
+ }
+ if fh != nil {
+ t.Errorf("FormFile file header = %q, want nil", fh, nil)
+ }
+ if err != ErrMissingFile {
+ t.Errorf("FormFile err = %q, want nil", err, ErrMissingFile)
+ }
+}
+
func newTestMultipartRequest(t *testing.T) *Request {
b := bytes.NewBufferString(strings.Replace(message, "\n", "\r\n", -1))
req, err := NewRequest("POST", "/", b)
@@ -218,6 +241,9 @@ func validateTestMultipartContents(t *testing.T, req *Request, allMem bool) {
if g, e := req.FormValue("texta"), textaValue; g != e {
t.Errorf("texta value = %q, want %q", g, e)
}
+ if g := req.FormValue("missing"); g != "" {
+ t.Errorf("missing value = %q, want empty string", g)
+ }
assertMem := func(n string, fd multipart.File) {
if _, ok := fd.(*os.File); ok {
@@ -234,6 +260,8 @@ func validateTestMultipartContents(t *testing.T, req *Request, allMem bool) {
t.Errorf("fileb has unexpected underlying type %T", fd)
}
}
+
+ testMissingFile(t, req)
}
func testMultipartFile(t *testing.T, req *Request, key, expectFilename, expectContent string) multipart.File {