1
0
mirror of https://github.com/golang/go synced 2024-11-26 09:48:14 -07:00

mime: allow duplicate media type parameters with equivalent values

Fixes #48866

Change-Id: I2bd2c806e44eb4064b1fb9a6509d79cecbbef013
Reviewed-on: https://go-review.googlesource.com/c/go/+/363094
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Tim King <taking@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
Paschalis Tsilias 2021-11-10 22:14:03 +02:00 committed by Damien Neil
parent 296c40dbbe
commit dba9323f76
2 changed files with 6 additions and 3 deletions

View File

@ -180,8 +180,8 @@ func ParseMediaType(v string) (mediatype string, params map[string]string, err e
pmap = continuation[baseName]
}
}
if _, exists := pmap[key]; exists {
// Duplicate parameter name is bogus.
if v, exists := pmap[key]; exists && v != value {
// Duplicate parameter names are incorrect, but we allow them if they are equal.
return "", nil, errors.New("mime: duplicate parameter name")
}
pmap[key] = value

View File

@ -407,8 +407,11 @@ func TestParseMediaType(t *testing.T) {
`message/external-body`,
m("access-type", "URL", "url", "ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"),
},
}
// Issue #48866: duplicate parameters containing equal values should be allowed
{`text; charset=utf-8; charset=utf-8; format=fixed`, "text", m("charset", "utf-8", "format", "fixed")},
{`text; charset=utf-8; format=flowed; charset=utf-8`, "text", m("charset", "utf-8", "format", "flowed")},
}
for _, test := range tests {
mt, params, err := ParseMediaType(test.in)
if err != nil {