diff --git a/binding/json.go b/binding/json.go index d62e0705..b2b92b14 100644 --- a/binding/json.go +++ b/binding/json.go @@ -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) } diff --git a/binding/json_test.go b/binding/json_test.go index fbd5c527..acb504ef 100644 --- a/binding/json_test.go +++ b/binding/json_test.go @@ -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) +}