Make sorting lists by name/title case-insensitive (#2993)

* Make sort by order_* fields case-insensitive.

* Sort internet radios by name case-insensitive
This commit is contained in:
Deluan Quintão 2024-05-09 07:08:15 -04:00 committed by GitHub
parent 6408dda948
commit c4b05dac28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 52 additions and 28 deletions

View file

@ -3,6 +3,7 @@ package utils
import (
"strings"
"github.com/deluan/sanitize"
"github.com/navidrome/navidrome/conf"
)
@ -32,3 +33,13 @@ func LongestCommonPrefix(list []string) string {
}
return list[0]
}
func SanitizeFieldForSorting(originalValue string) string {
v := strings.TrimSpace(sanitize.Accents(originalValue))
return strings.ToLower(v)
}
func SanitizeFieldForSortingNoArticle(originalValue string) string {
v := strings.TrimSpace(sanitize.Accents(originalValue))
return strings.ToLower(NoArticle(v))
}

View file

@ -35,6 +35,35 @@ var _ = Describe("Strings", func() {
})
})
Describe("sanitizeFieldForSorting", func() {
BeforeEach(func() {
conf.Server.IgnoredArticles = "The O"
})
It("sanitize accents", func() {
Expect(SanitizeFieldForSorting("Céu")).To(Equal("ceu"))
})
It("removes articles", func() {
Expect(SanitizeFieldForSorting("The Beatles")).To(Equal("the beatles"))
})
It("removes accented articles", func() {
Expect(SanitizeFieldForSorting("Õ Blésq Blom")).To(Equal("o blesq blom"))
})
})
Describe("SanitizeFieldForSortingNoArticle", func() {
BeforeEach(func() {
conf.Server.IgnoredArticles = "The O"
})
It("sanitize accents", func() {
Expect(SanitizeFieldForSortingNoArticle("Céu")).To(Equal("ceu"))
})
It("removes articles", func() {
Expect(SanitizeFieldForSortingNoArticle("The Beatles")).To(Equal("beatles"))
})
It("removes accented articles", func() {
Expect(SanitizeFieldForSortingNoArticle("Õ Blésq Blom")).To(Equal("blesq blom"))
})
})
Describe("LongestCommonPrefix", func() {
It("finds the longest common prefix", func() {
Expect(LongestCommonPrefix(testPaths)).To(Equal("/Music/iTunes 1/iTunes Media/Music/"))