Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-1080] Update truncation logic for strings #1105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]) + "..."
raghavaggarwal2308 marked this conversation as resolved.
Show resolved Hide resolved
}
return s[:max]
return string(runes[:max])
}
Loading