mirror of
https://github.com/gin-gonic/gin.git
synced 2025-05-22 20:49:23 +08:00
Merge 924e4f49a04ed250f4a51160ab7d2bf8483e39c8 into 674522db91d637d179c16c372d87756ea26fa089
This commit is contained in:
commit
2b6ebf4a4a
@ -50,6 +50,9 @@ func decodeJSON(r io.Reader, obj any) error {
|
||||
decoder.DisallowUnknownFields()
|
||||
}
|
||||
if err := decoder.Decode(obj); err != nil {
|
||||
if err == io.EOF {
|
||||
return errors.New("empty body")
|
||||
}
|
||||
return err
|
||||
}
|
||||
return validate(obj)
|
||||
|
@ -5,6 +5,7 @@
|
||||
package binding
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -28,3 +29,11 @@ func TestJSONBindingBindBodyMap(t *testing.T) {
|
||||
assert.Equal(t, "FOO", s["foo"])
|
||||
assert.Equal(t, "world", s["hello"])
|
||||
}
|
||||
|
||||
func TestJSONBindingBindEmpty(t *testing.T) {
|
||||
var s struct {
|
||||
Foo string `binding:"required"`
|
||||
}
|
||||
err := jsonBinding{}.BindBody([]byte(""), &s)
|
||||
require.True(t, strings.Contains(err.Error(), "empty body"))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user