fix: sanitize bug where / is converted to -
Some checks failed
build / build (push) Has been cancelled

This commit is contained in:
Viktor Varland 2025-10-03 09:18:18 +02:00
parent a639ac073e
commit 3e32707400
Signed by: varl
GPG key ID: 7459F0B410115EE8
2 changed files with 30 additions and 1 deletions

View file

@ -140,8 +140,19 @@ func (o Organizer) ProcessEpisodes(episodes []metadata.EpisodeAsset) error {
}
func safeName(name string) string {
replacer := strings.NewReplacer("/", "-", "\\", "-", ":", "-", "?", "", "*", "", "\"", "", "<", "", ">", "", "|", "")
replacer := strings.NewReplacer(
"/", "",
"\\", "",
":", "",
"?", "",
"*", "",
"\"", "",
"<", "",
">", "",
"|", "",
)
sanitized := replacer.Replace(strings.TrimSpace(name))
sanitized = strings.Trim(sanitized, " .-_")
if sanitized == "" {
return "unknown"
}

View file

@ -118,3 +118,21 @@ func TestOrganizerProcess(t *testing.T) {
t.Fatalf("expected show info removed, got err=%v", err)
}
}
func TestSafeNameTrimsLeadingSeparators(t *testing.T) {
if got := safeName("-noclip"); got != "noclip" {
t.Fatalf("expected 'noclip', got %q", got)
}
if got := safeName("/noclip"); got != "noclip" {
t.Fatalf("expected 'noclip', got %q", got)
}
if got := safeName(" __Example__ "); got != "Example" {
t.Fatalf("expected 'Example', got %q", got)
}
if got := safeName(" "); got != "unknown" {
t.Fatalf("expected fallback 'unknown', got %q", got)
}
}