fix: sanitize bug where / is converted to -
Some checks failed
build / build (push) Has been cancelled
Some checks failed
build / build (push) Has been cancelled
This commit is contained in:
parent
a639ac073e
commit
3e32707400
|
|
@ -140,8 +140,19 @@ func (o Organizer) ProcessEpisodes(episodes []metadata.EpisodeAsset) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func safeName(name string) string {
|
func safeName(name string) string {
|
||||||
replacer := strings.NewReplacer("/", "-", "\\", "-", ":", "-", "?", "", "*", "", "\"", "", "<", "", ">", "", "|", "")
|
replacer := strings.NewReplacer(
|
||||||
|
"/", "",
|
||||||
|
"\\", "",
|
||||||
|
":", "",
|
||||||
|
"?", "",
|
||||||
|
"*", "",
|
||||||
|
"\"", "",
|
||||||
|
"<", "",
|
||||||
|
">", "",
|
||||||
|
"|", "",
|
||||||
|
)
|
||||||
sanitized := replacer.Replace(strings.TrimSpace(name))
|
sanitized := replacer.Replace(strings.TrimSpace(name))
|
||||||
|
sanitized = strings.Trim(sanitized, " .-_")
|
||||||
if sanitized == "" {
|
if sanitized == "" {
|
||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -118,3 +118,21 @@ func TestOrganizerProcess(t *testing.T) {
|
||||||
t.Fatalf("expected show info removed, got err=%v", err)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue