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

encoding/json: Panic when parsing JSON strings containing slashes #46115

Closed
bt opened this issue May 12, 2021 · 3 comments
Closed

encoding/json: Panic when parsing JSON strings containing slashes #46115

bt opened this issue May 12, 2021 · 3 comments

Comments

@bt
Copy link

bt commented May 12, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16.3 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

I'm trying to parse some SSL certificate metadata and encountered this error when decoding/unmarshaling from a JSON file containing the following input string:

"CN=Go Daddy Secure Certificate Authority - G2,OU=http://certs.godaddy.com/repository/,O=GoDaddy.com\, Inc.,L=Scottsdale,ST=Arizona,C=US"

After further investigation, I found it to be related to the following lines: https://github.com/golang/go/blob/master/src/encoding/json/scanner.go#L340-L343 -- it's expecting that a slash will correspond to an escaped quote " character, but this is not always the case.

Relevant Go Playground Link: https://play.golang.org/p/tovEHscZFes

What did you expect to see?

The above input string should be parsed to:

CN=Go Daddy Secure Certificate Authority - G2,OU=http://certs.godaddy.com/repository/,O=GoDaddy.com\, Inc.,L=Scottsdale,ST=Arizona,C=US

What did you see instead?

You will get the following panic:

panic: invalid character ',' in string escape code
@davecheney
Copy link
Contributor

Thank you for raising this issue. It looks like the panic is coming from your error handling code, not the json package. What is the issue here? Is it the panic, or a difficulty parsing json? If it’s the latter the issue tracker may not be the best place for this discussion.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For asking questions, see:

@bt
Copy link
Author

bt commented May 12, 2021

Hi @davecheney, thanks for the reply.

I think I might be experiencing a bug with an upstream library that relies on encoding/json but the error is making it look like it's a bug with encoding/json. Let me do a bit more investigation on my part and confirm.

@bt bt closed this as completed May 12, 2021
@davecheney
Copy link
Contributor

\, is not a valid json string. It must be encoded.

@golang golang locked and limited conversation to collaborators May 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants