Commit e0e28d2b authored by Pascal S. de Kloe's avatar Pascal S. de Kloe Committed by Brad Fitzpatrick

mime: lower-case media type parameters

        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
parent 7a471ead
......@@ -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
}
......
......@@ -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; ` +
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment