fix: address code review findings

This commit is contained in:
2026-07-19 18:59:38 +03:00
parent 8a5b58a817
commit a4c426f640
3 changed files with 33 additions and 6 deletions

View File

@@ -37,8 +37,13 @@ func NormalizeString(s string) string {
// Remove parenthesized content (e.g., (Deluxe), (Remastered))
s = parenRe.ReplaceAllString(s, "")
// Remove years (4-digit numbers between 1000-2999)
s = yearRe.ReplaceAllString(s, "")
// Remove years (4-digit numbers between 1000-2999). If stripping the
// year would empty the entire string (e.g. an album literally titled
// "1989" or "2112"), keep the original form so the title can still match.
stripped := yearRe.ReplaceAllString(s, "")
if strings.TrimSpace(stripped) != "" {
s = stripped
}
// Replace common separators with spaces before stripping other special chars
s = strings.ReplaceAll(s, "-", " ")

View File

@@ -36,6 +36,9 @@ func TestNormalizeString_Basic(t *testing.T) {
// Digits that are not years should stay
{"30 Seconds to Mars", "30 seconds to mars"},
{"1941 - The Greatest Hits", "the greatest hits"},
// Year-only title is preserved (not collapsed to empty) so it can still match
{"1989", "1989"},
{"2112", "2112"},
}
for _, tt := range tests {