From 3e327074001750e196b73e5b08831c2da5ee20c0 Mon Sep 17 00:00:00 2001 From: Viktor Varland Date: Fri, 3 Oct 2025 09:18:18 +0200 Subject: [PATCH] fix: sanitize bug where `/` is converted to `-` --- internal/organize/organize.go | 13 ++++++++++++- internal/organize/organize_test.go | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/internal/organize/organize.go b/internal/organize/organize.go index fbc2161..fae6bbe 100644 --- a/internal/organize/organize.go +++ b/internal/organize/organize.go @@ -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" } diff --git a/internal/organize/organize_test.go b/internal/organize/organize_test.go index dc5094f..6355de6 100644 --- a/internal/organize/organize_test.go +++ b/internal/organize/organize_test.go @@ -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) + } +}