mirror of
https://github.com/gin-gonic/gin.git
synced 2026-11-23 11:33:37 +08:00
Merge dd1789e324a5208fda98472bae98df8c9a70e5f6 into 3b08cd7235bd5ad2f055aa9e38135f111f6c5926
This commit is contained in:
commit
637994a024
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user