You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
render/json.go defines AsciiJSON and some internal names jsonContentType, jsonpContentType, jsonAsciiContentType. This shows a misunderstanding of RFC4627 section 3: "JSON text SHALL be encoded in Unicode".
From the RFC, it follows
the content type application/json implies that the content is UTF-8 or UTF-16 or UTF-32 - the RFC describes how the decoder detects the correct UTF from the first bytes.
it is not helpful to use the term ASCII, even if the JSON content happens to be an ASCII-subset of UTF-8
AsciiJSON doesn't do what its name suggests. It should be deprecated (and later removed)
Because Go strings are UTF-8 by default, it is equally correct to use the content-type with charset (application/json;charset=utf-8) and without charset (application/json). The longer form takes a few more bytes but eliminates the (tiny) chance of there being a faulty decoder at the other end and it getting it wrong.
But if someone wants to force the encoding to be some other UTF (e.g. UTF-16 for Asian content), there isn't a way to do that in Gin and maybe that's what is needed. For Asian content, the advantage would be that the UTF-16 encoding would take fewer bytes (a bit less than two-thirds) than UTF-8 encoding for the same content.
So perhaps replace AsciiJSON with JSON_UTF16LE and JSON_UTF16BE. The render methods would need to ensure that the written content is correctly transcoded into the chosen UTF-16 encoding.
The text was updated successfully, but these errors were encountered:
render/json.go defines
AsciiJSON
and some internal namesjsonContentType
,jsonpContentType
,jsonAsciiContentType
. This shows a misunderstanding of RFC4627 section 3: "JSON text SHALL be encoded in Unicode".From the RFC, it follows
application/json
implies that the content is UTF-8 or UTF-16 or UTF-32 - the RFC describes how the decoder detects the correct UTF from the first bytes.AsciiJSON
doesn't do what its name suggests. It should be deprecated (and later removed)Because Go strings are UTF-8 by default, it is equally correct to use the content-type with charset (
application/json;charset=utf-8
) and without charset (application/json
). The longer form takes a few more bytes but eliminates the (tiny) chance of there being a faulty decoder at the other end and it getting it wrong.But if someone wants to force the encoding to be some other UTF (e.g. UTF-16 for Asian content), there isn't a way to do that in Gin and maybe that's what is needed. For Asian content, the advantage would be that the UTF-16 encoding would take fewer bytes (a bit less than two-thirds) than UTF-8 encoding for the same content.
So perhaps replace
AsciiJSON
withJSON_UTF16LE
andJSON_UTF16BE
. The render methods would need to ensure that the written content is correctly transcoded into the chosen UTF-16 encoding.The text was updated successfully, but these errors were encountered: