forked from forgejo/forgejo
Add tests for EllipsisString() and fix bug if param length < 3
This commit is contained in:
parent
f81711f40d
commit
030ba2894f
2 changed files with 16 additions and 5 deletions
|
@ -462,7 +462,10 @@ func Subtract(left interface{}, right interface{}) interface{} {
|
|||
// EllipsisString returns a truncated short string,
|
||||
// it appends '...' in the end of the length of string is too large.
|
||||
func EllipsisString(str string, length int) string {
|
||||
if len(str) < length {
|
||||
if length <= 3 {
|
||||
return "..."
|
||||
}
|
||||
if len(str) <= length {
|
||||
return str
|
||||
}
|
||||
return str[:length-3] + "..."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue