fix(scanner): normalize attribute strings and add edge case tests for PID calculation
Relates to https://github.com/navidrome/navidrome/issues/4183#issuecomment-2952729458 Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
@@ -24,6 +24,7 @@ type hashFunc = func(...string) string
|
|||||||
func createGetPID(hash hashFunc) func(mf model.MediaFile, md Metadata, spec string) string {
|
func createGetPID(hash hashFunc) func(mf model.MediaFile, md Metadata, spec string) string {
|
||||||
var getPID func(mf model.MediaFile, md Metadata, spec string) string
|
var getPID func(mf model.MediaFile, md Metadata, spec string) string
|
||||||
getAttr := func(mf model.MediaFile, md Metadata, attr string) string {
|
getAttr := func(mf model.MediaFile, md Metadata, attr string) string {
|
||||||
|
attr = strings.TrimSpace(strings.ToLower(attr))
|
||||||
switch attr {
|
switch attr {
|
||||||
case "albumid":
|
case "albumid":
|
||||||
return getPID(mf, md, conf.Server.PID.Album)
|
return getPID(mf, md, conf.Server.PID.Album)
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ var _ = Describe("getPID", func() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("calculated attributes", func() {
|
Context("calculated attributes", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
DeferCleanup(configtest.SetupConfig())
|
DeferCleanup(configtest.SetupConfig())
|
||||||
@@ -114,4 +115,36 @@ var _ = Describe("getPID", func() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Context("edge cases", func() {
|
||||||
|
When("the spec has spaces between groups", func() {
|
||||||
|
It("should return the pid", func() {
|
||||||
|
spec := "albumartist| Album"
|
||||||
|
md.tags = map[model.TagName][]string{
|
||||||
|
"album": {"album name"},
|
||||||
|
}
|
||||||
|
Expect(getPID(mf, md, spec)).To(Equal("(album name)"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
When("the spec has spaces", func() {
|
||||||
|
It("should return the pid", func() {
|
||||||
|
spec := "albumartist, album"
|
||||||
|
md.tags = map[model.TagName][]string{
|
||||||
|
"albumartist": {"Album Artist"},
|
||||||
|
"album": {"album name"},
|
||||||
|
}
|
||||||
|
Expect(getPID(mf, md, spec)).To(Equal("(Album Artist\\album name)"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
When("the spec has mixed case fields", func() {
|
||||||
|
It("should return the pid", func() {
|
||||||
|
spec := "albumartist,Album"
|
||||||
|
md.tags = map[model.TagName][]string{
|
||||||
|
"albumartist": {"Album Artist"},
|
||||||
|
"album": {"album name"},
|
||||||
|
}
|
||||||
|
Expect(getPID(mf, md, spec)).To(Equal("(Album Artist\\album name)"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user