diff --git a/core/share.go b/core/share.go index 530c6e324..c46b40a95 100644 --- a/core/share.go +++ b/core/share.go @@ -4,7 +4,6 @@ import ( "context" "strings" "time" - "unicode/utf8" "github.com/Masterminds/squirrel" "github.com/deluan/rest" @@ -121,8 +120,19 @@ func (r *shareRepositoryWrapper) Save(entity interface{}) (string, error) { return "", model.ErrNotFound } - if utf8.RuneCountInString(s.Contents) > 30 { - s.Contents = string([]rune(s.Contents)[:26]) + "..." + var runeCount int + var truncateIndex int + + for i := range s.Contents { + runeCount++ + + if runeCount == 27 { + truncateIndex = i + } + } + + if runeCount > 30 { + s.Contents = s.Contents[:truncateIndex] + "..." } id, err = r.Persistable.Save(s)