mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-18 23:12:17 +08:00
decodeJSON is now checking buffer data after JSON payload
This commit is contained in:
parent
b01605bb5b
commit
fac39d6bde
@ -52,5 +52,10 @@ func decodeJSON(r io.Reader, obj interface{}) error {
|
|||||||
if err := decoder.Decode(obj); err != nil {
|
if err := decoder.Decode(obj); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if decoder.More() {
|
||||||
|
return fmt.Errorf("invalid character after the JSON data")
|
||||||
|
}
|
||||||
|
|
||||||
return validate(obj)
|
return validate(obj)
|
||||||
}
|
}
|
||||||
|
@ -28,3 +28,9 @@ func TestJSONBindingBindBodyMap(t *testing.T) {
|
|||||||
assert.Equal(t, "FOO", s["foo"])
|
assert.Equal(t, "FOO", s["foo"])
|
||||||
assert.Equal(t, "world", s["hello"])
|
assert.Equal(t, "world", s["hello"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestJSONForeignSymbols(t *testing.T) {
|
||||||
|
s := make(map[string]string)
|
||||||
|
err := jsonBinding{}.BindBody([]byte(`{}text`), &s)
|
||||||
|
require.Error(t, err)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user