From 600e60f3c41fddc06a81408b4495506a746b4059 Mon Sep 17 00:00:00 2001 From: zomo Date: Tue, 1 Jul 2025 02:16:10 -0500 Subject: [PATCH] fix: no more slashes in template variables --- main.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index f47aa1d..1af46d2 100644 --- a/main.go +++ b/main.go @@ -93,8 +93,6 @@ func mainPath(directory string) error { return err } - // parse $DATA - files, err := os.ReadDir(directory) if err != nil { return err @@ -336,9 +334,9 @@ func doMoveTagged(filePath string, fileTags tag.Metadata) error { } tmplDataPath := LibTemplatePath{ - Album: fileTags.Album(), - AlbumArtist: fileTags.AlbumArtist(), - Genre: fileTags.Genre(), + Album: cleanTemplateVariable(fileTags.Album()), + AlbumArtist: cleanTemplateVariable(fileTags.AlbumArtist()), + Genre: cleanTemplateVariable(fileTags.Genre()), Year: fileTags.Year(), } @@ -367,9 +365,9 @@ func doMoveTaggedPathonly(filePath string, albumTags tag.Metadata) error { tmplPath := template.Must(template.New("libPath").Parse(libTemplatePath)) tmplData := LibTemplatePath{ - Album: albumTags.Album(), - AlbumArtist: albumTags.AlbumArtist(), - Genre: albumTags.Genre(), + Album: cleanTemplateVariable(albumTags.Album()), + AlbumArtist: cleanTemplateVariable(albumTags.AlbumArtist()), + Genre: cleanTemplateVariable(albumTags.Genre()), Year: albumTags.Year(), } @@ -451,3 +449,8 @@ func cleanPath(str string) string { re := regexp.MustCompile(`[<>:"|?*]`) return re.ReplaceAllString(str, "") } + +func cleanTemplateVariable(str string) string { + re := regexp.MustCompile(`[<>:"|?*/\\]`) + return re.ReplaceAllString(str, "") +}