[go] mime: reject duplicate formatted parameter names

4 views
Skip to first unread message

shuang cui (Gerrit)

unread,
Jun 13, 2026, 9:41:18โ€ฏAMJun 13
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

shuang cui has uploaded the change for review

Commit message

mime: reject duplicate formatted parameter names

FormatMediaType lower-cases parameter names when serializing.
If the input map contains keys that differ only by case, it
can emit duplicate parameter names such as "name=foo; name=bar",
which ParseMediaType rejects. Return an empty string in this case,
matching FormatMediaType's documented behavior for invalid output.
Change-Id: I6d0890bf608da8c3a18af60a36b1825f8dc88ce9

Change diff

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"},

Change information

Files:
  • M src/mime/mediatype.go
  • M src/mime/mediatype_test.go
Change size: XS
Delta: 2 files changed, 8 insertions(+), 1 deletion(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I6d0890bf608da8c3a18af60a36b1825f8dc88ce9
Gerrit-Change-Number: 790400
Gerrit-PatchSet: 1
Gerrit-Owner: shuang cui <imc...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

shuang cui (Gerrit)

unread,
Jun 13, 2026, 9:43:17โ€ฏAMJun 13
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

shuang cui voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I6d0890bf608da8c3a18af60a36b1825f8dc88ce9
Gerrit-Change-Number: 790400
Gerrit-PatchSet: 1
Gerrit-Owner: shuang cui <imc...@gmail.com>
Gerrit-Reviewer: shuang cui <imc...@gmail.com>
Gerrit-Comment-Date: Sat, 13 Jun 2026 13:43:06 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

shuang cui (Gerrit)

unread,
Jun 15, 2026, 8:43:57โ€ฏAMJun 15
to goph...@pubsubhelper.golang.org, David Chase, Neal Patel, golang...@luci-project-accounts.iam.gserviceaccount.com, Damien Neil, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Damien Neil

shuang cui added 1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
shuang cui . resolved

Hi, Would you mind review this PR at your convenience? Thank you very much.

Open in Gerrit

Related details

Attention is currently required from:
  • Damien Neil
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I6d0890bf608da8c3a18af60a36b1825f8dc88ce9
Gerrit-Change-Number: 790400
Gerrit-PatchSet: 1
Gerrit-Owner: shuang cui <imc...@gmail.com>
Gerrit-Reviewer: Damien Neil <dn...@google.com>
Gerrit-Reviewer: shuang cui <imc...@gmail.com>
Gerrit-CC: David Chase <drc...@google.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-CC: Michael Knyszek <mkny...@google.com>
Gerrit-CC: Neal Patel <ne...@golang.org>
Gerrit-Attention: Damien Neil <dn...@google.com>
Gerrit-Comment-Date: Mon, 15 Jun 2026 12:43:50 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
satisfied_requirement
open
diffy

shuang cui (Gerrit)

unread,
Jun 16, 2026, 1:13:46โ€ฏPMJun 16
to goph...@pubsubhelper.golang.org, David Chase, Neal Patel, golang...@luci-project-accounts.iam.gserviceaccount.com, Damien Neil, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Damien Neil

shuang cui voted Commit-Queue+1

Commit-Queue+1
Gerrit-Comment-Date: Tue, 16 Jun 2026 17:13:37 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Sean Liao (Gerrit)

unread,
6:58โ€ฏPMย (4 hours ago)ย 6:58โ€ฏPM
to shuang cui, goph...@pubsubhelper.golang.org, David Chase, Neal Patel, golang...@luci-project-accounts.iam.gserviceaccount.com, Damien Neil, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Damien Neil and shuang cui

Sean Liao voted

Auto-Submit+1
Code-Review+2
Open in Gerrit

Related details

Attention is currently required from:
  • Damien Neil
  • shuang cui
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I6d0890bf608da8c3a18af60a36b1825f8dc88ce9
Gerrit-Change-Number: 790400
Gerrit-PatchSet: 1
Gerrit-Owner: shuang cui <imc...@gmail.com>
Gerrit-Reviewer: Damien Neil <dn...@google.com>
Gerrit-Reviewer: Sean Liao <se...@liao.dev>
Gerrit-Reviewer: shuang cui <imc...@gmail.com>
Gerrit-CC: David Chase <drc...@google.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-CC: Michael Knyszek <mkny...@google.com>
Gerrit-CC: Neal Patel <ne...@golang.org>
Gerrit-Attention: Damien Neil <dn...@google.com>
Gerrit-Attention: shuang cui <imc...@gmail.com>
Gerrit-Comment-Date: Fri, 17 Jul 2026 22:57:58 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages