Skip to content

Commit

Permalink
Add tests for the sanitizeFilename function
Browse files Browse the repository at this point in the history
This commit introduces a series of tests for the sanitizeFilename function in msgwriter_test.go. The tests cover various edge cases to ensure filenames are sanitized correctly by replacing or removing invalid characters. These additions will help maintain the integrity and reliability of filename sanitization in the codebase.
  • Loading branch information
wneessen committed Nov 26, 2024
1 parent 8f8b507 commit b051471
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions msgwriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,3 +676,33 @@ func TestMsgWriter_writeBody(t *testing.T) {
}
})
}

func TestMsgWriter_sanitizeFilename(t *testing.T) {
tests := []struct {
given string
want string
}{
{"test.txt", "test.txt"},
{"test file.txt", "test file.txt"},
{"test\\ file.txt", "test_ file.txt"},
{`"test" file.txt`, "_test_ file.txt"},
{`test file .txt`, "test_file_.txt"},
{"test\r\nfile.txt", "test__file.txt"},
{"test\x22file.txt", "test_file.txt"},
{"test\x2ffile.txt", "test_file.txt"},
{"test\x3afile.txt", "test_file.txt"},
{"test\x3cfile.txt", "test_file.txt"},
{"test\x3efile.txt", "test_file.txt"},
{"test\x3ffile.txt", "test_file.txt"},
{"test\x5cfile.txt", "test_file.txt"},
{"test\x7cfile.txt", "test_file.txt"},
{"test\x7ffile.txt", "test_file.txt"},
}
for _, tt := range tests {
t.Run(tt.given+"=>"+tt.want, func(t *testing.T) {
if got := sanitizeFilename(tt.given); got != tt.want {
t.Errorf("sanitizeFilename failed, expected: %q, got: %q", tt.want, got)
}
})
}
}

0 comments on commit b051471

Please sign in to comment.