Skip to content

Commit

Permalink
[GH-1080] Update truncation logic for strings
Browse files Browse the repository at this point in the history
  • Loading branch information
raghavaggarwal2308 committed Jul 24, 2024
1 parent 98af6b8 commit bd8cb82
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions server/webhook_jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"fmt"
"strings"
"unicode/utf8"

"github.com/andygrunwald/go-jira"
"github.com/pkg/errors"
Expand Down Expand Up @@ -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])
}

0 comments on commit bd8cb82

Please sign in to comment.