mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 13:22:09 +08:00
panic on NegotiateFormat - index out of range
This commit is contained in:
parent
a0acf1df28
commit
ff9e36d0a3
@ -1146,7 +1146,7 @@ func (c *Context) NegotiateFormat(offered ...string) string {
|
||||
// According to RFC 2616 and RFC 2396, non-ASCII characters are not allowed in headers,
|
||||
// therefore we can just iterate over the string without casting it into []rune
|
||||
i := 0
|
||||
for ; i < len(accepted); i++ {
|
||||
for ; i < len(accepted) && i < len(offer); i++ {
|
||||
if accepted[i] == '*' || offer[i] == '*' {
|
||||
return offer
|
||||
}
|
||||
|
@ -1311,6 +1311,14 @@ func TestContextNegotiationFormatCustom(t *testing.T) {
|
||||
assert.Equal(t, MIMEJSON, c.NegotiateFormat(MIMEJSON))
|
||||
}
|
||||
|
||||
func TestContextNegotiationFormat2(t *testing.T) {
|
||||
c, _ := CreateTestContext(httptest.NewRecorder())
|
||||
c.Request, _ = http.NewRequest("POST", "/", nil)
|
||||
c.Request.Header.Add("Accept", "image/tiff-fx")
|
||||
|
||||
assert.Equal(t, "", c.NegotiateFormat("image/tiff"))
|
||||
}
|
||||
|
||||
func TestContextIsAborted(t *testing.T) {
|
||||
c, _ := CreateTestContext(httptest.NewRecorder())
|
||||
assert.False(t, c.IsAborted())
|
||||
|
Loading…
x
Reference in New Issue
Block a user