Skip to content

Commit

Permalink
Merge pull request #413 from elindsey/master
Browse files Browse the repository at this point in the history
do not add a '~' when filename is not truncated
  • Loading branch information
boyter authored Nov 3, 2023
2 parents 7a6bd11 + a5e8b04 commit 39672f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion processor/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ func unicodeAwareTrim(tmp string, size int) string {
// iterate all the runes so we can cut off correctly and get the correct length
r := []rune(tmp)

if len(r) >= size {
if len(r) > size {
for runewidth.StringWidth(tmp) > size {
// remove character one at a time till we get the length we want
tmp = string([]rune(tmp)[1:])
Expand Down
8 changes: 8 additions & 0 deletions processor/formatters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,14 @@ func TestUnicodeAwareTrimAscii(t *testing.T) {
}
}

func TestUnicodeAwareTrimExactSizeAscii(t *testing.T) {
tmp := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.md"
res := unicodeAwareTrim(tmp, len(tmp))
if res != tmp {
t.Errorf("expected %s got %s", tmp, res)
}
}

func TestUnicodeAwareTrimUnicode(t *testing.T) {
tmp := "中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文.md"
res := unicodeAwareTrim(tmp, shortFormatFileTruncate)
Expand Down

0 comments on commit 39672f9

Please sign in to comment.