From e8d0f2ec2c4342156f8306474a86cbdf66128663 Mon Sep 17 00:00:00 2001 From: Deluan Date: Fri, 13 Sep 2024 18:04:21 -0400 Subject: [PATCH] Allow searching songs by filepath, for songs without Title --- utils/str/sanitize_strings.go | 4 +++- utils/str/sanitize_strings_test.go | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/utils/str/sanitize_strings.go b/utils/str/sanitize_strings.go index de28c9fd1..463659c0c 100644 --- a/utils/str/sanitize_strings.go +++ b/utils/str/sanitize_strings.go @@ -11,7 +11,8 @@ import ( "github.com/navidrome/navidrome/conf" ) -var quotesRegex = regexp.MustCompile("[“”‘’'\"\\[\\(\\{\\]\\)\\}]") +var quotesRegex = regexp.MustCompile("[“”‘’'\"\\[({\\])}]") +var slashRemover = strings.NewReplacer("\\", " ", "/", " ") func SanitizeStrings(text ...string) string { sanitizedText := strings.Builder{} @@ -25,6 +26,7 @@ func SanitizeStrings(text ...string) string { var fullText []string for w := range words { w = quotesRegex.ReplaceAllString(w, "") + w = slashRemover.Replace(w) if w != "" { fullText = append(fullText, w) } diff --git a/utils/str/sanitize_strings_test.go b/utils/str/sanitize_strings_test.go index 9f0d3f793..6f5b180ec 100644 --- a/utils/str/sanitize_strings_test.go +++ b/utils/str/sanitize_strings_test.go @@ -32,6 +32,9 @@ var _ = Describe("Sanitize Strings", func() { It("remove opening brackets", func() { Expect(str.SanitizeStrings("[Five Years]")).To(Equal("five years")) }) + It("remove slashes", func() { + Expect(str.SanitizeStrings("folder/file\\yyyy")).To(Equal("folder file yyyy")) + }) }) Describe("SanitizeFieldForSorting", func() {