From 4874b67d0a2e367f751b8acfbb0e3c42f393260b Mon Sep 17 00:00:00 2001 From: glowinthedark Date: Wed, 30 Aug 2023 18:04:49 +0200 Subject: [PATCH] fix: escape regexes to handle special characters in file names (#2592) --- files/file.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/files/file.go b/files/file.go index 4d754260..63655556 100644 --- a/files/file.go +++ b/files/file.go @@ -296,7 +296,8 @@ func (i *FileInfo) detectSubtitles() { // TODO: give subtitles descriptive names (lang) and track attributes parentDir := strings.TrimRight(i.Path, i.Name) // pattern to match against .*\.(vtt|srt) - subsRegex := regexp.MustCompile("(?i)" + strings.TrimSuffix(filepath.Base(i.Name), filepath.Ext(i.Name)) + ".*\\.(vtt|srt)$") + baseName := strings.TrimSuffix(filepath.Base(i.Name), filepath.Ext(i.Name)) + subsRegex := regexp.MustCompile("(?i)" + regexp.QuoteMeta(baseName) + ".*\\.(vtt|srt)$") subsFoldersRegex := regexp.MustCompile(`(?i)\bsub(s|titles)$`) // find .vtt/.srt files in current dir or nested folders, Subtitles/Subs/subtitles/subs