Sanitize non utf8 strings before returning them to iOS apps

In swift, strings must be strictly utf8, and when golang
returns a string with non utf8 characters, it gets translated to
an empty string for utf8.
To avoid this situation, we sanitize strings before returning them.
This behavior is only enabled when building with the "ios" build tag.
This commit is contained in:
M. Thiercelin 2022-10-31 15:18:24 +01:00
parent 6021e54d03
commit a2fd1c6a3b
No known key found for this signature in database
GPG key ID: 29581E7E24EBEC0A
4 changed files with 21 additions and 2 deletions

View file

@ -202,7 +202,7 @@ func (msg *PlainMessage) GetBinary() []byte {
// GetString returns the content of the message as a string.
func (msg *PlainMessage) GetString() string {
return strings.ReplaceAll(string(msg.Data), "\r\n", "\n")
return sanitizeString(strings.ReplaceAll(string(msg.Data), "\r\n", "\n"))
}
// GetBase64 returns the base-64 encoded binary content of the message as a