summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2011-11-03 17:21:58 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2011-11-03 17:21:58 -0700
commitf812a46b31008ef46e2db76b259e93caa09bc501 (patch)
tree4ec0419854fc9482da22e12c74b4a344e382d7b8
parent1ce1592d4407d1705cf08f3a7512874bcff7979a (diff)
downloadgo-f812a46b31008ef46e2db76b259e93caa09bc501.tar.gz
http: only recognize application/x-www-form-urlencoded in ParseForm
R=golang-dev, dsymonds CC=golang-dev http://codereview.appspot.com/5322070
-rw-r--r--src/pkg/net/http/request.go2
-rw-r--r--src/pkg/net/http/request_test.go19
2 files changed, 7 insertions, 14 deletions
diff --git a/src/pkg/net/http/request.go b/src/pkg/net/http/request.go
index d9a04efe3..7a62dcede 100644
--- a/src/pkg/net/http/request.go
+++ b/src/pkg/net/http/request.go
@@ -734,7 +734,7 @@ func (r *Request) ParseForm() (err error) {
ct := r.Header.Get("Content-Type")
ct, _, err := mime.ParseMediaType(ct)
switch {
- case ct == "text/plain" || ct == "application/x-www-form-urlencoded" || ct == "":
+ case ct == "application/x-www-form-urlencoded":
var reader io.Reader = r.Body
maxFormSize := int64(1<<63 - 1)
if _, ok := r.Body.(*maxBytesReader); !ok {
diff --git a/src/pkg/net/http/request_test.go b/src/pkg/net/http/request_test.go
index 9be9efcc8..d6487e197 100644
--- a/src/pkg/net/http/request_test.go
+++ b/src/pkg/net/http/request_test.go
@@ -29,12 +29,10 @@ func TestQuery(t *testing.T) {
}
func TestPostQuery(t *testing.T) {
- req := &Request{Method: "POST"}
- req.URL, _ = url.Parse("http://www.google.com/search?q=foo&q=bar&both=x")
- req.Header = Header{
- "Content-Type": {"application/x-www-form-urlencoded; boo!"},
- }
- req.Body = ioutil.NopCloser(strings.NewReader("z=post&both=y"))
+ req, _ := NewRequest("POST", "http://www.google.com/search?q=foo&q=bar&both=x",
+ strings.NewReader("z=post&both=y"))
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded; param=value")
+
if q := req.FormValue("q"); q != "foo" {
t.Errorf(`req.FormValue("q") = %q, want "foo"`, q)
}
@@ -49,7 +47,6 @@ func TestPostQuery(t *testing.T) {
type stringMap map[string][]string
type parseContentTypeTest struct {
contentType stringMap
- err bool
}
var parseContentTypeTests = []parseContentTypeTest{
@@ -58,11 +55,10 @@ var parseContentTypeTests = []parseContentTypeTest{
{contentType: stringMap{"Content-Type": {"text/plain; boundary="}}},
{
contentType: stringMap{"Content-Type": {"application/unknown"}},
- err: true,
},
}
-func TestPostContentTypeParsing(t *testing.T) {
+func TestParseFormBadContentType(t *testing.T) {
for i, test := range parseContentTypeTests {
req := &Request{
Method: "POST",
@@ -70,10 +66,7 @@ func TestPostContentTypeParsing(t *testing.T) {
Body: ioutil.NopCloser(bytes.NewBufferString("body")),
}
err := req.ParseForm()
- if !test.err && err != nil {
- t.Errorf("test %d: Unexpected error: %v", i, err)
- }
- if test.err && err == nil {
+ if err == nil {
t.Errorf("test %d should have returned error", i)
}
}