-
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: misleading error for end-of-input in an escape sequence #58680
Comments
I think the root case of the issue is the function below: func (s *scanner) eof() int {
if s.err != nil {
return scanError
}
if s.endTop {
return scanEnd
}
s.step(s, ' ')
if s.endTop {
return scanEnd
}
if s.err == nil {
s.err = &SyntaxError{"unexpected end of JSON input", s.bytes}
}
return scanError
} I do update |
I have an experimental CL in progress that completely switches the "encoding/json" parser to a new implementation, which will fix most (if not all) of these weird error cases. |
I guess I should mention that I'm finding these issues by fuzzing my own JSON parser against In particular, |
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?
I fed the JSON parser a truncated JSON document that has a backslash as the final rune.
https://go.dev/play/p/KxvQ6lpnT7I
What did you expect to see?
I expected the error to be
unexpected end of JSON input
What did you see instead?
I saw the error
character in the input at all!
invalid character ' ' in string escape code
, which is a nonsense error as there is nojson.Compact
andjson.Indent
have the same issue, whilejson.Decoder.Decode
correctly returnsio.ErrUnexpectedEOF
.The text was updated successfully, but these errors were encountered: