News for hackers. Stuff that matters.
Re:Golang's network stack attempts to parse HTTP headers as ... by Thaxll on Thursday January 21, 2021 @08:32AM (#25858596)
In Go a string is an immutable byte slice not UTF-8.
Re:Golang's network stack attempts to parse HTTP headers as ... by jrimbault on Thursday January 21, 2021 @08:35AM (#25858626)
I'll also play along the role of the pedant :

> In a go a string is an immutable byte slice assumed to be valid utf8, with associated methods and users which all assume that slice of memory is valid utf8.

Which is in my opinion the worst choice you could make when designing a type. If I'm working in a typed language because of so-called "type safety", if I can't trust my types to actually enforce their guarantees, what can I trust ?

Re:Golang's network stack attempts to parse HTTP headers as ... by papaf on Thursday January 21, 2021 @08:52AM (#25858741)
Its a common mistake to assume strings are UTF-8 but it is a mistake.

This is not a defence of Go but more of a warning to Go programmers.

Re:Golang's network stack attempts to parse HTTP headers as ... by adonovan on Thursday January 21, 2021 @12:14PM (#25861291)
Exactly. It's a convention, not a law of physics. If a string's UTF-8 validity is important to the correctness of your function, check it. It's not expensive.