I'm having trouble with something in Go and I'm not sure where to look. I'm fetching a UTF-8 string from a MySQL database, and attempting to return it in a JSON response to a client.
Different clients react differently, but iOS NSJSONSerialization
returns an "Unescaped control character" error. This breaks the whole application. I can decode the JSON without issue in Chrome using JSON.parse()
, though.
On the server-side, this same generator function written in another language besides Go works fine. Help?
EDIT: Here is the JSON that is causing the issue:
{ "test":"☮️" }
... If I omit this emoji, it works. If it's there, it doesn't work. The issue seems to be something related to there being two different encodings for certain emoji. One seems to trip up Go, but they are both valid.
To demonstrate the difference in encoding, some of the emoji show up in the database explorer and some do not:
... These ones that appear in the database explorer are causing this issue with 100% reproducibility. However, all of them usually appear in the actual client software (not the database explorer) without issue. I don't know if there's a way to reconfigure the database connection to avoid this (or something), but it seems to work with different instances depending on what is doing the decoding and how forgiving it is. Considering that users could type or copy/paste either encoding... this needs to work consistently.
Any help would be appreciated. Thanks in advance.