From bd8cb823b4869c821c7d1dfc7dcc62ea1046b161 Mon Sep 17 00:00:00 2001 From: raghavaggarwal2308 Date: Wed, 24 Jul 2024 20:02:07 +0530 Subject: [PATCH] [GH-1080] Update truncation logic for strings --- server/webhook_jira.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/webhook_jira.go b/server/webhook_jira.go index ca5d1a6b3..e15c6e422 100644 --- a/server/webhook_jira.go +++ b/server/webhook_jira.go @@ -6,6 +6,7 @@ package main import ( "fmt" "strings" + "unicode/utf8" "github.com/andygrunwald/go-jira" "github.com/pkg/errors" @@ -191,11 +192,12 @@ func mdUser(user *jira.User) string { } func truncate(s string, max int) string { - if len(s) <= max || max < 0 { + if utf8.RuneCountInString(s) <= max || max < 0 { return s } + runes := []rune(s) if max > 3 { - return s[:max-3] + "..." + return string(runes[:max-3]) + "..." } - return s[:max] + return string(runes[:max]) }