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: ",string" bool field accepts "terrible" as true #15146
Comments
The error message is correct: it's an invalid use of the |
yes,
but now encoding/json does not report the error message, and we got
is it right??? |
but now the result is
A is "" and B is true I think it is a bug! |
Let's move this discussion to a forum. See https://golang.org/wiki/Questions You're obviously looking something, but whatever it is, I don't think it's the |
I think it's the go/src/encoding/json/decode.go Line 1071 in 853f1a1
golang-nuts topic is: |
It is definitely a bug. Why it be closed? |
so it should get a err, not a struct. |
This looks like a bug. Also decoding bool field with ",string" tag doesn't looks correct: tra-la-la is decoded to true. http://play.golang.org/p/upVyInopWQ
|
@kostya-sh, thanks! I've reopened this bug and edited the original bug report's header to link to your example. |
This is not bug(maybe?)
@bradfitz If you think this is bug? |
This example shows the difference in error handling while decoding fields with and without ",string" tag: http://play.golang.org/p/RatENpHcvP There are 3 problems as far as I can see (with ",string" tag):
|
The single letter check is not meant to intentionally accept "terrible" as true and "factual" as false. It is simply a mistake introduced when ,string was added. Originally the JSON parser was only letting true, false, and null through to that case, so looking at the first letter was sufficient. But the ,string code started passing arbitrary strings to that code and didn't first check to see if that was appropriate. Just a bug, not intended, nothing more. Should be easy to fix. Thanks for the simple case @kostya-sh. |
CL https://golang.org/cl/23315 mentions this issue. |
CL https://golang.org/cl/30943 mentions this issue. |
EDIT by @bradfitz: see below in comment #15146 (comment) ; Original bug report follows...
Please answer these questions before submitting your issue. Thanks!
go version
)?go env
)?If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
http://play.golang.org/p/Jmzo5N4kHV
like
The text was updated successfully, but these errors were encountered: