Merge f6c0ff96d82a3c945dbadc03b47c9ec6c5b6da9f into 1bd0ecf2d3e08da37efa270bb7be20c1eddb0d68

This commit is contained in:
sb123sb123 2026-09-25 09:51:25 +02:00 committed by GitHub
commit 58294dc391
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View File

@ -955,6 +955,9 @@ func (c *Context) ShouldBindBodyWith(obj any, bb binding.BindingBody) (err error
}
}
if body == nil {
if c.Request.Body == nil {
return errors.New("cannot read nil body")
}
body, err = io.ReadAll(c.Request.Body)
if err != nil {
return err

View File

@ -2772,6 +2772,15 @@ func TestContextShouldBindBodyWith(t *testing.T) {
}
}
func TestContextShouldBindBodyWithNilBody(t *testing.T) {
c, _ := CreateTestContext(httptest.NewRecorder())
c.Request = &http.Request{}
var obj struct{}
err := c.ShouldBindBodyWithJSON(&obj)
assert.EqualError(t, err, "cannot read nil body")
}
func TestContextShouldBindBodyWithJSON(t *testing.T) {
for _, tt := range []struct {
name string