From dba9323f764e1ded627a0e3a459377026e9e0ce3 Mon Sep 17 00:00:00 2001 From: Paschalis Tsilias Date: Wed, 10 Nov 2021 22:14:03 +0200 Subject: [PATCH] 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 Reviewed-by: Tim King TryBot-Result: Gopher Robot Run-TryBot: Damien Neil Reviewed-by: David Chase --- src/mime/mediatype.go | 4 ++-- src/mime/mediatype_test.go | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mime/mediatype.go b/src/mime/mediatype.go index 6c1b095065a..bc8d417e628 100644 --- a/src/mime/mediatype.go +++ b/src/mime/mediatype.go @@ -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 diff --git a/src/mime/mediatype_test.go b/src/mime/mediatype_test.go index 079c080db71..1458cdb6e2d 100644 --- a/src/mime/mediatype_test.go +++ b/src/mime/mediatype_test.go @@ -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 {