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

Leading zeros is not allowed in rfc7159 #408

Closed
zycbobby opened this issue Feb 27, 2024 · 0 comments
Closed

Leading zeros is not allowed in rfc7159 #408

zycbobby opened this issue Feb 27, 2024 · 0 comments

Comments

@zycbobby
Copy link

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?

@ugorji ugorji closed this as completed in 07c54c2 Mar 7, 2024
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