json-iterator / go

A high-performance 100% compatible drop-in replacement of "encoding/json"
http://jsoniter.com/migrate-from-go-std.html
MIT License
13.43k stars 1.03k forks source link

Incompatible behavior with `encoding/json` when object key is a leading-zero number string #594

Open dysuby opened 2 years ago

dysuby commented 2 years ago

go version: 1.15.9 jsoniter version: v1.1.12 go test:

func TestJSON(t *testing.T) {
    j := "{\"0123\": 1}"

    data := map[int64]int64{}
    err := json.Unmarshal([]byte(j), &data)
    if err != nil {
        t.Errorf("std lib error: %v", err)
    } else {
        t.Logf("std lib success: %v", data)
    }

    err = jsoniter.ConfigCompatibleWithStandardLibrary.UnmarshalFromString(j, &data)
    if err != nil {
        t.Errorf("jsoniter lib error: %v", err)
    }
}

output:

std lib success: map[123:1]
jsoniter lib error: ReadMapCB: expect ", but found 1, error found in #4 byte of ...|{"0123": 1}|..., bigger context ...|{"0123": 1}|...