From ed981690f82cfad3d2a94654956bed5b705161d1 Mon Sep 17 00:00:00 2001 From: Branden J Brown Date: Sat, 31 Aug 2024 01:49:47 -0400 Subject: [PATCH] brain: fix panic on @ at end of message --- brain/words.go | 3 +++ brain/words_test.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/brain/words.go b/brain/words.go index 0885819..c60efc5 100644 --- a/brain/words.go +++ b/brain/words.go @@ -33,6 +33,9 @@ func Tokens(dst []string, msg string) []string { // write for a case that will be uncommon. // In terms of control flow, we can fall through to the next case, // after we skip past the @ itself. + if l == len(msg) { + break + } l++ fallthrough case unicode.Is(ln, c): diff --git a/brain/words_test.go b/brain/words_test.go index cbb5608..e1936f7 100644 --- a/brain/words_test.go +++ b/brain/words_test.go @@ -53,6 +53,11 @@ func TestWords(t *testing.T) { msg: "@bocchi ryo", want: s("@bocchi ", "ryo "), }, + { + name: "at-end", + msg: "bocchi@", + want: s("bocchi", "@ "), + }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) {