Skip to content

Commit 361d76c

Browse files
authored
🐛 bug: Fix MIME type equality checks (#3602)
1 parent ea66fe2 commit 361d76c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

helpers.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,12 @@ func acceptsOfferType(spec, offerType string, specParams headerParams) bool {
245245
}
246246

247247
s := strings.IndexByte(mimetype, '/')
248+
specSlash := strings.IndexByte(spec, '/')
248249
// Accept: <MIME_type>/*
249-
if strings.HasPrefix(spec, mimetype[:s]) && (spec[s:] == "/*" || mimetype[s:] == "/*") {
250-
return paramsMatch(specParams, offerParams)
250+
if s != -1 && specSlash != -1 {
251+
if utils.EqualFold(spec[:specSlash], mimetype[:s]) && (spec[specSlash:] == "/*" || mimetype[s:] == "/*") {
252+
return paramsMatch(specParams, offerParams)
253+
}
251254
}
252255

253256
return false

helpers_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ func Test_Utils_AcceptsOfferType(t *testing.T) {
243243
offerType: "application/xml",
244244
accepts: false,
245245
},
246+
{
247+
description: "mismatch with subtype prefix",
248+
spec: "application/json",
249+
offerType: "application/json+xml",
250+
accepts: false,
251+
},
246252
{
247253
description: "params match",
248254
spec: "application/json",

0 commit comments

Comments
 (0)