Smail/backend/controllers/attachments_test.go
smail 6de4a1cae3
Some checks are pending
Security Checks / security (push) Waiting to run
统一修复未知收件人超管限定与全部控制器Unicode转义
2026-09-10 22:27:27 +08:00

31 lines
860 B
Go

package controllers
import (
"strings"
"testing"
)
func TestSafeDownloadName(t *testing.T) {
for input, expected := range map[string]string{
"report.txt": "report.txt",
"../report.txt": ".._report.txt",
"report\r\nX-Test: value": "report__X-Test: value",
"": "attachment",
"..": "attachment",
} {
if got := safeDownloadName(input); got != expected {
t.Fatalf("safeDownloadName(%q) = %q, want %q", input, got, expected)
}
}
}
func TestSafeDownloadNameLength(t *testing.T) {
input := strings.Repeat("a", 300)
if got := safeDownloadName(input); len([]rune(got)) != 180 {
t.Fatalf("unexpected filename length: %d", len([]rune(got)))
}
if got := safeDownloadName("中文-report.txt"); got != "中文-report.txt" {
t.Fatalf("unicode filename changed: %q", got)
}
}