ffjson
ffjson copied to clipboard
ffjson accepts invalid JSON on UnmarshalFast and Unmarshal
The JSON specification states that objects keys must be strings. However, ffjson will accept object keys that are not strings. This can be seen in the attached test case. (Generated code not attached.)
foo.go
package ffjsontest
type Foo struct {
Values map[uint64]string
}
foo_test.go
package ffjsontest
import (
"encoding/json"
"testing"
"github.com/pquerna/ffjson/ffjson"
)
func TestFFJSONUnmarshal(t *testing.T) {
data := []byte(`{"Values":{0:"hello",1:"world"}}`)
foo := Foo{}
if err := json.Unmarshal(data, &foo); err == nil {
t.Error("json.Unmarshal: expected error")
}
if err := ffjson.Unmarshal(data, &foo); err == nil {
t.Error("ffjson.Unmarshal: expected error")
}
if err := ffjson.UnmarshalFast(data, &foo); err == nil {
t.Error("ffjson.UnmarshalFast: expected error")
}
}
$ go test
--- FAIL: TestFFJSONUnmarshal (0.00s)
foo_test.go:18: ffjson.Unmarshal: expected error
foo_test.go:22: ffjson.UnmarshalFast: expected error
FAIL
exit status 1