commit 7001394
delthas
·
2022-10-08 10:42:40 +0000 UTC
parent 300bf7a
Replace non-UTF8 chars with the Unicode replacement character tcell does not handle non-UTF8 chars well, so we explicitly replace them when getting the messages to avoid passing them to tcell down the line.
1 files changed,
+3,
-0
+3,
-0
1@@ -4,6 +4,8 @@ import (
2 "bufio"
3 "fmt"
4 "net"
5+ "strings"
6+ "unicode"
7 )
8
9 const chanCapacity = 64
10@@ -16,6 +18,7 @@ func ChanInOut(conn net.Conn) (in <-chan Message, out chan<- Message) {
11 r := bufio.NewScanner(conn)
12 for r.Scan() {
13 line := r.Text()
14+ line = strings.ToValidUTF8(line, string([]rune{unicode.ReplacementChar}))
15 msg, err := ParseMessage(line)
16 if err != nil {
17 continue