]> Cypherpunks repositories - gostls13.git/commitdiff
mime: lower-case media type parameters
authorPascal S. de Kloe <pascal@quies.net>
Fri, 24 Jun 2011 18:32:06 +0000 (11:32 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 24 Jun 2011 18:32:06 +0000 (11:32 -0700)
        RFC 1521 section 4 states "The type, subtype, and parameter names are not case sensitive.".

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/4648047

src/pkg/mime/mediatype.go
src/pkg/mime/mediatype_test.go

index a270cb9370b713135011d2082b1a48834ce36050..96edbd672590e2e9d12e9e2f924384bccbf6986c 100644 (file)
@@ -32,10 +32,12 @@ func validMediaTypeOrDisposition(s string) bool {
 
 // ParseMediaType parses a media type value and any optional
 // parameters, per RFC 1521.  Media types are the values in
-// Content-Type and Content-Disposition headers (RFC 2183).  On
-// success, ParseMediaType returns the media type converted to
-// lowercase and trimmed of white space and a non-nil params.  On
-// error, it returns an empty string and a nil params.
+// Content-Type and Content-Disposition headers (RFC 2183).
+// On success, ParseMediaType returns the media type converted
+// to lowercase and trimmed of white space. The returned params
+// is always a non-nil map. Params maps from the lowercase
+// attribute to the attribute value with its case preserved.
+// On error, it returns an empty string and a nil params.
 func ParseMediaType(v string) (mediatype string, params map[string]string) {
        i := strings.Index(v, ";")
        if i == -1 {
@@ -211,6 +213,7 @@ func consumeMediaParam(v string) (param, value, rest string) {
        rest = rest[1:] // consume semicolon
        rest = strings.TrimLeftFunc(rest, unicode.IsSpace)
        param, rest = consumeToken(rest)
+       param = strings.ToLower(param)
        if param == "" {
                return "", "", v
        }
index 454ddd037781e618a7e4776d44544968fba8e031..93264bd09a126f0bb120e92cb85ef7cc67056080 100644 (file)
@@ -60,6 +60,7 @@ func TestConsumeMediaParam(t *testing.T) {
                {" ; foo=bar", "foo", "bar", ""},
                {"; foo=bar", "foo", "bar", ""},
                {";foo=bar", "foo", "bar", ""},
+               {";FOO=bar", "foo", "bar", ""},
                {`;foo="bar"`, "foo", "bar", ""},
                {`;foo="bar"; `, "foo", "bar", "; "},
                {`;foo="bar"; foo=baz`, "foo", "bar", "; foo=baz"},
@@ -127,7 +128,7 @@ func TestParseMediaType(t *testing.T) {
                        `URL*1="cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"`,
                        "message/external-body",
                        m("access-type", "URL",
-                               "URL", "ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar")},
+                               "url", "ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar")},
 
                {`application/x-stuff; ` +
                        `title*0*=us-ascii'en'This%20is%20even%20more%20; ` +