mirror of
https://github.com/gin-gonic/gin.git
synced 2026-11-25 20:43:43 +08:00
Merge dd1789e324a5208fda98472bae98df8c9a70e5f6 into 0f09c3a9b4626d9fe9979cf4d0521d6ae32ab646
This commit is contained in:
commit
6b0c32418c
@ -1473,7 +1473,7 @@ func (c *Context) NegotiateFormat(offered ...string) string {
|
||||
break
|
||||
}
|
||||
}
|
||||
if i == len(accepted) {
|
||||
if i == len(accepted) && i == len(offer) {
|
||||
return offer
|
||||
}
|
||||
}
|
||||
|
||||
@ -4055,3 +4055,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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user