Merge dd1789e324a5208fda98472bae98df8c9a70e5f6 into 3b08cd7235bd5ad2f055aa9e38135f111f6c5926

This commit is contained in:
Alexandre Rodrigues 2026-09-19 17:12:39 -04:00 committed by GitHub
commit 637994a024
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -1474,7 +1474,7 @@ func (c *Context) NegotiateFormat(offered ...string) string {
break
}
}
if i == len(accepted) {
if i == len(accepted) && i == len(offer) {
return offer
}
}

View File

@ -4031,3 +4031,23 @@ func BenchmarkGetMapFromFormData(b *testing.B) {
})
}
}
func TestContextNegotiateFormatDoesNotMatchPrefixes(t *testing.T) {
for _, tc := range []struct {
accepted string
offered string
want string
}{
{"application/json", "application/json-seq", ""},
{"application/json-seq", "application/json", ""},
{"text/plain", "text/plaintext", ""},
{"application/json", "application/json", "application/json"},
{"application/*", "application/json-seq", "application/json-seq"},
} {
t.Run(tc.accepted+"/"+tc.offered, func(t *testing.T) {
c, _ := CreateTestContext(httptest.NewRecorder())
c.SetAccepted(tc.accepted)
assert.Equal(t, tc.want, c.NegotiateFormat(tc.offered))
})
}
}