From 75a6ceca84f2b496ea9ffbbb5e19d2a2fb9c8bf1 Mon Sep 17 00:00:00 2001 From: Azareal Date: Wed, 18 Jul 2018 16:36:16 +1000 Subject: [PATCH] Added a missing bounds check in peekMatch. --- common/parser.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/parser.go b/common/parser.go index 1899022d..b4fdfc60 100644 --- a/common/parser.go +++ b/common/parser.go @@ -171,6 +171,7 @@ type TagToAction struct { PartialMode bool } +// TODO: Write a test for this func tryStepForward(i int, step int, runes []rune) (int, bool) { i += step if i < len(runes) { @@ -387,6 +388,9 @@ func peekMatch(cur int, phrase string, runes []rune) bool { return false } for i, char := range phrase { + if cur+i+1 >= len(runes) { + return false + } if runes[cur+i+1] != char { return false } @@ -396,6 +400,7 @@ func peekMatch(cur int, phrase string, runes []rune) bool { // TODO: Write a test for this // TODO: We need a lot more hooks here. E.g. To add custom media types and handlers. +// TODO: Use templates to reduce the amount of boilerplate? func ParseMessage(msg string, sectionID int, sectionType string /*, user User*/) string { msg = strings.Replace(msg, ":)", "😀", -1) msg = strings.Replace(msg, ":(", "😞", -1)