Some checks are pending
Security Checks / security (push) Waiting to run
统一 frontend、backend、test、test-log 和 out 目录,更新构建、部署及测试入口;纳入配置管理兼容与首次安全引导修复;排除本机配置、密钥和测试产物。
31 lines
872 B
Go
31 lines
872 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("\u4e2d\u6587-report.txt"); got != "\u4e2d\u6587-report.txt" {
|
|
t.Fatalf("unicode filename changed: %q", got)
|
|
}
|
|
}
|