fix: strip null bytes from ID3v2 TXXX/UFID tag values
The dhowden/tag library's Comm.Text and UFID.Identifier fields include trailing null bytes from the C-style strings in the ID3v2 binary format. strings.TrimSpace doesn't strip \x00, so MBIDs stored from MP3 files had invisible null bytes appended. This caused WHERE mbid = ? queries to fail — the stored value 'uuid\x00' didn't match the clean 'uuid' from search results. FLAC files (Vorbis comments with plain strings) were unaffected. Fix: use strings.TrimRight with explicit \x00 in the cutset. Requires a full rescan to fix existing corrupted MBIDs.
This commit is contained in:
@@ -148,13 +148,14 @@ func extractMBIDs(raw map[string]interface{}, meta *TrackMetadata) {
|
||||
case *tag.Comm:
|
||||
// ID3v2 TXXX frames — Description is the tag name.
|
||||
if val != nil && val.Description != "" {
|
||||
normalized[strings.ToLower(val.Description)] = strings.TrimSpace(val.Text)
|
||||
text := strings.TrimRight(val.Text, "\x00 \t\n\r")
|
||||
normalized[strings.ToLower(val.Description)] = text
|
||||
}
|
||||
|
||||
case *tag.UFID:
|
||||
// ID3v2 UFID frame — MusicBrainz recording ID.
|
||||
if val != nil && val.Provider == "http://musicbrainz.org" {
|
||||
meta.RecordingMBID = strings.TrimSpace(string(val.Identifier))
|
||||
meta.RecordingMBID = strings.TrimRight(string(val.Identifier), "\x00 \t\n\r")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user