Skip to content

Send and receive SMS messages using your Android phone programmatically via a simple HTTP API

fix: allow A-Z, underscore, and dash in SanitizeFilename

Acho Arnold4158509abf60
diff --git a/api/pkg/repositories/attachment_repository.go b/api/pkg/repositories/attachment_repository.go
index f5540cb5..11d80e20 100644
--- a/api/pkg/repositories/attachment_repository.go
+++ b/api/pkg/repositories/attachment_repository.go
@@ -83,8 +83,8 @@ func SanitizeFilename(name string, index int) string {
name = strings.TrimSuffix(name, filepath.Ext(name))
var builder strings.Builder
- for _, r := range strings.ToLower(name) {
- if (r >= 'a' && r <= 'z') || (r >= '0' && r <= '9') {
+ for _, r := range name {
+ if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '_' || r == '-' {
builder.WriteRune(r)
} else if r == ' ' {
builder.WriteRune('-')
diff --git a/api/pkg/repositories/attachment_repository_test.go b/api/pkg/repositories/attachment_repository_test.go
index 76cc5adc..1b29fa68 100644
--- a/api/pkg/repositories/attachment_repository_test.go
+++ b/api/pkg/repositories/attachment_repository_test.go
@@ -43,13 +43,13 @@ func TestSanitizeFilename(t *testing.T) {
{"photo.jpg", 0, "photo"},
{"../../etc/passwd", 0, "etcpasswd"},
{"hello/world\\test", 0, "helloworldtest"},
- {"normal_file", 0, "normalfile"},
+ {"normal_file", 0, "normal_file"},
{"", 0, "attachment-0"},
{" ", 0, "attachment-0"},
{"...", 1, "attachment-1"},
- {"My Photo", 0, "my-photo"},
+ {"My Photo", 0, "My-Photo"},
{"file name with spaces.png", 0, "file-name-with-spaces"},
- {"UPPER_CASE", 0, "uppercase"},
+ {"UPPER_CASE", 0, "UPPER_CASE"},
{"special!@#chars", 0, "specialchars"},
}
for _, tt := range tests {