ugorji / go

idiomatic codec and rpc lib for msgpack, cbor, json, etc. msgpack.org[Go]
MIT License
1.86k stars 295 forks source link

Leading zeros is not allowed in rfc7159 #408

Closed zycbobby closed 8 months ago

zycbobby commented 9 months ago

As I check in https://datatracker.ietf.org/doc/html/rfc7159,

The representation of numbers is similar to that used in most programming languages. A number is represented in base 10 using decimal digits. It contains an integer component that may be prefixed with an optional minus sign, which may be followed by a fraction part and/or an exponent part. Leading zeros are not allowed.

but it looks like github.com/ugorji/go can parse leading zero number as a valid one

package main

import (
    "fmt"

    "github.com/ugorji/go/codec"
)

type A struct {
    Score float64 `json:"score"`
}

func main() {
    str := `
    {
        "score": 08
    }`

    a := A{}

    codec.NewDecoderBytes([]byte(str), new(codec.JsonHandle)).Decode(&a)

    fmt.Println(a.Score)
}

it outputs

╰─$ go run main.go
8

I am using


module json

go 1.18

require github.com/ugorji/go/codec v1.2.12

It(this bug/feature) is not that important to my project, I am just wondering if there is some consideration in implementation lead to this bug/feature, which can achieve a better performance for json encode/decode?