diff --git a/src/mime/mediatype.go b/src/mime/mediatype.go
index c6006b6..520bcb7 100644
--- a/src/mime/mediatype.go
+++ b/src/mime/mediatype.go
@@ -34,6 +34,7 @@
b.WriteString(strings.ToLower(sub))
}
+ seenAttrs := make(map[string]struct{}, len(param))
for _, attribute := range slices.Sorted(maps.Keys(param)) {
value := param[attribute]
b.WriteByte(';')
@@ -41,7 +42,12 @@
if !isToken(attribute) {
return ""
}
- b.WriteString(strings.ToLower(attribute))
+ attribute = strings.ToLower(attribute)
+ if _, ok := seenAttrs[attribute]; ok {
+ return ""
+ }
+ seenAttrs[attribute] = struct{}{}
+ b.WriteString(attribute)
needEnc := needsEncoding(value)
if needEnc {
diff --git a/src/mime/mediatype_test.go b/src/mime/mediatype_test.go
index da8d64d..343beb8 100644
--- a/src/mime/mediatype_test.go
+++ b/src/mime/mediatype_test.go
@@ -531,6 +531,7 @@
{"foo/BAR", map[string]string{"both": `With \backslash and "quote`}, `foo/bar; both="With \\backslash and \"quote"`},
{"foo/BAR", map[string]string{"": "empty attribute"}, ""},
{"foo/BAR", map[string]string{"bad attribute": "baz"}, ""},
+ {"foo/BAR", map[string]string{"Name": "foo", "name": "bar"}, ""},
{"foo/BAR", map[string]string{"nonascii": "not an ascii character: รค"}, "foo/bar; nonascii*=utf-8''not%20an%20ascii%20character%3A%20%C3%A4"},
{"foo/BAR", map[string]string{"ctl": "newline: \n nil: \000"}, "foo/bar; ctl*=utf-8''newline%3A%20%0A%20nil%3A%20%00"},
{"foo/bar", map[string]string{"a": "av", "b": "bv", "c": "cv"}, "foo/bar; a=av; b=bv; c=cv"},