Skip to content

Commit a5e8b04

Browse files
committed
do not add a '~' when filename is not truncated
This fixes an off-by-one when the filename length exactly matches our size limit. As an example, today if the filename size limit is one character and the filename is named "a", it will be incorrectly formatted as "~a" despite no truncation occuring.
1 parent 7a6bd11 commit a5e8b04

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

processor/formatters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ func unicodeAwareTrim(tmp string, size int) string {
931931
// iterate all the runes so we can cut off correctly and get the correct length
932932
r := []rune(tmp)
933933

934-
if len(r) >= size {
934+
if len(r) > size {
935935
for runewidth.StringWidth(tmp) > size {
936936
// remove character one at a time till we get the length we want
937937
tmp = string([]rune(tmp)[1:])

processor/formatters_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,14 @@ func TestUnicodeAwareTrimAscii(t *testing.T) {
13921392
}
13931393
}
13941394

1395+
func TestUnicodeAwareTrimExactSizeAscii(t *testing.T) {
1396+
tmp := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.md"
1397+
res := unicodeAwareTrim(tmp, len(tmp))
1398+
if res != tmp {
1399+
t.Errorf("expected %s got %s", tmp, res)
1400+
}
1401+
}
1402+
13951403
func TestUnicodeAwareTrimUnicode(t *testing.T) {
13961404
tmp := "中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文.md"
13971405
res := unicodeAwareTrim(tmp, shortFormatFileTruncate)

0 commit comments

Comments
 (0)