←back to thread

Go subtleties

(harrisoncramer.me)
235 points darccio | 1 comments | | HN request time: 0.224s | source
1. Groxx ◴[] No.45670073[source]
>As an additional complexity, although string literals are UTF-8 encoded, they are just aribtrary collections of bytes, which means you can technically have strings that have invalid data in them. In this case, Go replaces invalid UTF-8 data with replacement characters.

No, it's just doing the usual "replace unprintable characters when printing" behavior. The data is unchanged, you have no guarantees of UTF-8 validity at all: https://go.dev/play/p/IpYjcMqtmP0