diff --git a/processor/formatters.go b/processor/formatters.go index 8b17a06c..25cdad20 100644 --- a/processor/formatters.go +++ b/processor/formatters.go @@ -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:]) diff --git a/processor/formatters_test.go b/processor/formatters_test.go index 8c512e26..043f3914 100644 --- a/processor/formatters_test.go +++ b/processor/formatters_test.go @@ -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)