mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
fix(scanner): store MusicBrainz ids in their canonical form
uuid.Parse accepts a UUID wrapped in any two bytes, as well as braced and urn:
forms, but sanitize() returned the raw string. A tag like {<mbid>} or a quoted
value was therefore persisted with its wrapper into the mbz_* columns, where the
exact-match MBID search can never find it. The parsed value is now stored, which
also lowercases uppercase ids and adds the dashes to unhyphenated ones.
This commit is contained in:
parent
34e4b94251
commit
7e5fc1c8a6
@ -396,11 +396,14 @@ func sanitize(filePath string, tagName model.TagName, tag model.TagConf, value s
|
||||
return ""
|
||||
}
|
||||
case model.TagTypeUUID:
|
||||
_, err := uuid.Parse(value)
|
||||
u, err := uuid.Parse(value)
|
||||
if err != nil {
|
||||
log.Trace("Invalid UUID tag value", "tag", tagName, "value", value)
|
||||
return ""
|
||||
}
|
||||
// Store the canonical form: uuid.Parse accepts braces, urn: prefixes and any
|
||||
// two-byte wrapper, and a wrapped value would never match an exact-match query
|
||||
value = u.String()
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
@ -144,6 +144,22 @@ var _ = Describe("Metadata", func() {
|
||||
Expect(md.String(model.TagTitle)).To(HaveLen(1024))
|
||||
})
|
||||
|
||||
DescribeTable("should normalize UUID tags to their canonical form",
|
||||
func(raw, expected string) {
|
||||
props.Tags = model.RawTags{"musicbrainz_artistid": {raw}}
|
||||
md = metadata.New(filePath, props)
|
||||
|
||||
Expect(md.String(model.TagMusicBrainzArtistID)).To(Equal(expected))
|
||||
},
|
||||
Entry("canonical", "f81d4fae-7dec-11d0-a765-00a0c91e6bf6", "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"),
|
||||
Entry("uppercase", "F81D4FAE-7DEC-11D0-A765-00A0C91E6BF6", "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"),
|
||||
Entry("braced", "{f81d4fae-7dec-11d0-a765-00a0c91e6bf6}", "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"),
|
||||
Entry("urn prefix", "urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6", "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"),
|
||||
Entry("quoted", `"f81d4fae-7dec-11d0-a765-00a0c91e6bf6"`, "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"),
|
||||
Entry("no dashes", "f81d4fae7dec11d0a76500a0c91e6bf6", "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"),
|
||||
Entry("not a uuid", "the beatles", ""),
|
||||
)
|
||||
|
||||
It("should split multiple values", func() {
|
||||
props.Tags = model.RawTags{
|
||||
"Genre": {"Rock/Pop;;Punk"},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user