News for hackers. Stuff that matters.
Re:Golang's network stack attempts to parse HTTP headers as ... by jd3 on Thursday January 21, 2021 @10:00AM (#25859465)
I do love the simplicity of Go's UTF-8[0] approach, though this did also burn me when I was first learning the language and did not really understand the implication of it.

I translated an x-face encoder from js to go for one of my introductory projects and initially couldn't get the correct output from `b64.StdEncoding.EncodeToString` due to the fact that x-face strings are single-byte ASCII ISO-8859-1 encoded[1].

[0]: https://blog.golang.org/strings

[1]: https://stackoverflow.com/questions/43461679/escaping-of-hex...

Re:Golang's network stack attempts to parse HTTP headers as ... by jeff-davis on Thursday January 21, 2021 @12:29PM (#25861464)
After reading [0], I was left with the question: why not just have a utf-8 string type in addition to a byte string type?

Also, as a nit, I don't think iso-8859-1 is ASCII.

Re:Golang's network stack attempts to parse HTTP headers as ... by jd3 on Wednesday February 03, 2021 @12:00PM (#26015749)
> why not just have a utf-8 string type in addition to a byte string type?

I'm not a go expert, but my understanding is that go "strings" are really all just a series of bytes and it's the standard library functions which treat string operations as UTF-8 encoded by default. I think this reddit post[0] explains it nicely. I suppose the simplicity of "just work with the bytes and apply encoding when necessary" follows go's simplicity and composability/interface patterns well.

> Also, as a nit, I don't think iso-8859-1 is ASCII.

We're splitting hairs here, but ISO-8859-1 is the eight-bit extension to 7-bit ASCII, no? It includes the standard 128 ASCII characters + up to an additional 128 characters (191 in total for ISO-8859-1 Latin-1 Western European, iirc).

[0]: https://old.reddit.com/r/golang/comments/a5v3fn/are_strings_...