-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
encoding/json: accept float starting with "." (".85") while unmarshaling json with ,string tag #32117
Comments
That’s not valid json. See the number flow chart at http://json.org/ |
But I think this is specifically about the |
@bradfitz / @josharian does this need to be fixed? |
It is waiting for a decision to be made. That might take a while. There definitely won’t be any code changes for it in the next month and a half or so. Also, cc @mvdan |
Even with the It is simple for users to explain:
Rather than explaining something more obscure like:
One of the purposes of JSON is that it's a language agnostic data-interchange format and I think it's a mistake to leak Go-specific details in our implementation. It should theoretically be possible to rewrite a Go service using |
I strongly agree with @dsnet that we should reject this. If someone really wants to implement a more magic integer-inside-string type, they always can do it with the Marshaler/Unmarshaler interfaces. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Tried unmarshaling json that contained float string starting with "."
The playground link below contains 3 examples
https://play.golang.org/p/q4OFvV6Asxt
What did you expect to see?
I expect ".85" to be successfully converted to a float using unmarshal
".85" -> 0.85
What did you see instead?
this error:
json: invalid use of ,string struct tag, trying to unmarshal ".85" into float64
The text was updated successfully, but these errors were encountered: