From 96c8609e33fb656d2f30c02b87622681d3750c14 Mon Sep 17 00:00:00 2001 From: perennial Date: Sat, 12 Oct 2024 00:44:24 +1100 Subject: [PATCH] ParseEmojis: fix malformed strings --- server/template/templateFunctions.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/template/templateFunctions.go b/server/template/templateFunctions.go index ffcc4d2..3b0288a 100644 --- a/server/template/templateFunctions.go +++ b/server/template/templateFunctions.go @@ -95,8 +95,11 @@ func ParseEmojis(s string) HTML { // Replace shortcodes with corresponding image tags parsedString := regex.ReplaceAllStringFunc(s, func(s string) string { - s = s[1 : len(s)-1] // Get the string inside parentheses - id := emojiList[s] + s = s[1 : len(s)-1] // Get the string inside parentheses + id, found := emojiList[s] // Check if the string has a corresponding emoji ID + if !found { + return fmt.Sprintf("(%s)", s) // No replacement, return the original text + } return fmt.Sprintf(`(%s)`, id, s) })