Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffjson accepts invalid JSON on UnmarshalFast and Unmarshal #229

Open
echlebek opened this issue Sep 15, 2017 · 0 comments
Open

ffjson accepts invalid JSON on UnmarshalFast and Unmarshal #229

echlebek opened this issue Sep 15, 2017 · 0 comments

Comments

@echlebek
Copy link

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
@echlebek echlebek changed the title ffjson accepts invalid JSON on UnmarshalFast ffjson accepts invalid JSON on UnmarshalFast and Unmarshal Sep 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant