mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-27 07:55:08 +01:00
Add tests for the sanitizeFilename function
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.
This commit is contained in:
parent
8f8b5079c3
commit
b051471f8d
1 changed files with 30 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue