-
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: Unmarshal & json.(*Decoder).Token report different values for SyntaxError.Offset for the same input #34543
Comments
…nter of its internal scanner Decoder.Token() goes through the bytes of the JSON payload and return the next JSON token. When it encounters a token which isn't a square bracket, a curly bracket, a colon or a comma, it calls Decoder.Decode() to process it. This last function increments the decoder's internal scanner's byte counter on each byte it encounters. However, this increment isn't done if the character appears in the list mentioned previously. This causes the scanner's bytes counter to not correctly reflect the amount of bytes it has processed in the payload, and to show incoherent values when returning errors to the caller, e.g. with SyntaxError instances. Fixes golang#34543
…nter of its internal scanner Decoder.Token() goes through the bytes of the JSON payload and return the next JSON token. When it encounters a token which isn't a square bracket, a curly bracket, a colon or a comma, it calls Decoder.Decode() to process it. This last function increments the decoder's internal scanner's byte counter on each byte it encounters. However, this increment isn't done if the character appears in the list mentioned previously. This causes the scanner's bytes counter to not correctly reflect the amount of bytes it has processed in the payload, and to show incoherent values when returning errors to the caller, e.g. with SyntaxError instances. Fixes golang#34543
decoder.Token() goes through the bytes of the JSON payload and return the next JSON token. When it encounters a token which isn't a square bracket, a curly bracket, a colon or a comma, it calls decoder.Decode() to process it. This last function increments the decoder's internal scanner's byte counter on each byte it encounters. However, this increment isn't done if the character appears in the list mentioned previously. This causes the scanner's bytes counter to not correctly reflect the amount of bytes it has processed in the payload, and to show incoherent values when returning errors to the caller, e.g. with SyntaxError instances. Fixes golang#34543
Change https://golang.org/cl/198047 mentions this issue: |
The CL above could be the right fix, but it has no tests. If someone else wants to send a CL with a test, that would be helpful. |
Change https://golang.org/cl/284078 mentions this issue: |
Stream decoder does not count whitespaces, empty objects and arrays in syntax error offset. This change removes offset tracking from the scanner and relies on the calling code to provide the correct value. Fixes golang#44811, golang#34543
Change https://golang.org/cl/355729 mentions this issue: |
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?
https://play.golang.org/p/zkVEGITpYIo
What did you expect to see?
The same Offset for the two error cases, as it is the same input.
What did you see instead?
Different Offset.
The text was updated successfully, but these errors were encountered: