decodeJSON is now checking buffer data after JSON payload

This commit is contained in:
RadiumByte 2021-01-19 14:58:07 +03:00
parent b01605bb5b
commit fac39d6bde
2 changed files with 11 additions and 0 deletions

View File

@ -52,5 +52,10 @@ func decodeJSON(r io.Reader, obj interface{}) error {
if err := decoder.Decode(obj); err != nil {
return err
}
if decoder.More() {
return fmt.Errorf("invalid character after the JSON data")
}
return validate(obj)
}

View File

@ -28,3 +28,9 @@ func TestJSONBindingBindBodyMap(t *testing.T) {
assert.Equal(t, "FOO", s["foo"])
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)
}