Skip to content

Commit

Permalink
Fix bug in smast truncate
Browse files Browse the repository at this point in the history
  • Loading branch information
matrixik committed Sep 30, 2022
1 parent fb70068 commit c05c02d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions slug.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ func SubstituteRune(s string, sub map[rune]string) string {
}

func smartTruncate(text string) string {
if len(text) < MaxLength {
if len(text) <= MaxLength {
return text
}

// If slug is too long, we need to find the last '-' before MaxLength, and
// we cut there.
// If we don't find any, we have only one word, and we cut at MaxLength.
for i := MaxLength - 1; i >= 0; i-- {
for i := MaxLength; i >= 0; i-- {
if text[i] == '-' {
return text[:i]
}
Expand Down

0 comments on commit c05c02d

Please sign in to comment.