-
Notifications
You must be signed in to change notification settings - Fork 18k
encoding/json: add Encoder option to control escaping behavior #14749
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
Comments
JSON is not originally defined by ES6, and the current serialization
is perfectly valid JSON, so why should we change?
Also, the current behavior fixes a security concern where a browser
that incorrectly sniffs content might be tricked to interpret a JSON
document as HTML.
|
The reason for this behavior is explained here https://golang.org/pkg/encoding/json/#Marshal For the time being if this issue is blocking you, please see http://stackoverflow.com/a/25923407. |
Yes, this is perfectly legal JSON but hardly no other JSON serializer does this. The use case for following ES6 is enabling "crypto safe" JSON/JavaScript that can travel between different systems without getting corrupted: The best solution to this problem is offering different options/modes for serialization which I did in my Java implementation: |
Let's make this bug about adding a method on json.Encoder to change its quoting behavior. The default will be unchanged. (a method similar to https://golang.org/pkg/encoding/json/#Decoder.UseNumber or https://tip.golang.org/pkg/encoding/json/#Encoder.Indent) |
I can send a CL. (Or does this need more buy-in first?) |
Send a CL. It has a valid use case for JSON signing, etc. |
CL https://golang.org/cl/21796 mentions this issue. |
5.3
amd64,windows
{"trouble":"</script>"}
{"trouble":"\u003c/script\u003e"}
Related: #14135
Comment: In my JSON implementation for Java, I have made JavaScript serialization an option. When supplied as JavaScript the above does not break signatures (JSON.stringify() performs the normal serialization), but "on the wire" you should IMHO always use ES6: https://mailarchive.ietf.org/arch/msg/json/I2dF4osWAUlvax48WTxnAei3ldQ
The text was updated successfully, but these errors were encountered: