Skip to content

Commit 4158509

Browse files
AchoArnoldCopilot
andcommitted
fix: allow A-Z, underscore, and dash in SanitizeFilename
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 556234b commit 4158509

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

api/pkg/repositories/attachment_repository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ func SanitizeFilename(name string, index int) string {
8383
name = strings.TrimSuffix(name, filepath.Ext(name))
8484

8585
var builder strings.Builder
86-
for _, r := range strings.ToLower(name) {
87-
if (r >= 'a' && r <= 'z') || (r >= '0' && r <= '9') {
86+
for _, r := range name {
87+
if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '_' || r == '-' {
8888
builder.WriteRune(r)
8989
} else if r == ' ' {
9090
builder.WriteRune('-')

api/pkg/repositories/attachment_repository_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ func TestSanitizeFilename(t *testing.T) {
4343
{"photo.jpg", 0, "photo"},
4444
{"../../etc/passwd", 0, "etcpasswd"},
4545
{"hello/world\\test", 0, "helloworldtest"},
46-
{"normal_file", 0, "normalfile"},
46+
{"normal_file", 0, "normal_file"},
4747
{"", 0, "attachment-0"},
4848
{" ", 0, "attachment-0"},
4949
{"...", 1, "attachment-1"},
50-
{"My Photo", 0, "my-photo"},
50+
{"My Photo", 0, "My-Photo"},
5151
{"file name with spaces.png", 0, "file-name-with-spaces"},
52-
{"UPPER_CASE", 0, "uppercase"},
52+
{"UPPER_CASE", 0, "UPPER_CASE"},
5353
{"special!@#chars", 0, "specialchars"},
5454
}
5555
for _, tt := range tests {

0 commit comments

Comments
 (0)