Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not add a '~' when filename is not truncated #413

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading