diff options
Diffstat (limited to 'libgo/go/mime/mediatype.go')
-rw-r--r-- | libgo/go/mime/mediatype.go | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/libgo/go/mime/mediatype.go b/libgo/go/mime/mediatype.go index 2bf7978..41844c2 100644 --- a/libgo/go/mime/mediatype.go +++ b/libgo/go/mime/mediatype.go @@ -12,17 +12,22 @@ import ( "unicode" ) -// FormatMediaType serializes type t, subtype sub and the paramaters -// param as a media type conform RFC 2045 and RFC 2616. -// The type, subtype, and parameter names are written in lower-case. +// FormatMediaType serializes mediatype t and the parameters +// param as a media type conforming to RFC 2045 and RFC 2616. +// The type and parameter names are written in lower-case. // When any of the arguments result in a standard violation then // FormatMediaType returns the empty string. -func FormatMediaType(t, sub string, param map[string]string) string { - if !(IsToken(t) && IsToken(sub)) { +func FormatMediaType(t string, param map[string]string) string { + slash := strings.Index(t, "/") + if slash == -1 { + return "" + } + major, sub := t[:slash], t[slash+1:] + if !IsToken(major) || !IsToken(sub) { return "" } var b bytes.Buffer - b.WriteString(strings.ToLower(t)) + b.WriteString(strings.ToLower(major)) b.WriteByte('/') b.WriteString(strings.ToLower(sub)) |