mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-08 02:17:25 +02:00
When AppendSubtitle or AppendAlbumVersion is enabled, the subtitle/version
tag was always wrapped in parentheses and appended to the title/album name.
If the tag value already came wrapped in brackets (e.g. "(non-explicit
version)"), the result was doubled: "Title ((non-explicit version))".
Append the tag as-is when it is already wrapped in a matching bracket pair
- (), [], {} or <> - and trim surrounding whitespace first. The shared
appendSuffix helper is used by MediaFile.FullTitle, MediaFile.FullAlbumName
and Album.FullName so all consumers behave consistently.
54 lines
2 KiB
Go
54 lines
2 KiB
Go
package model_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/navidrome/navidrome/conf"
|
|
"github.com/navidrome/navidrome/conf/configtest"
|
|
. "github.com/navidrome/navidrome/model"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("Album", func() {
|
|
BeforeEach(func() {
|
|
DeferCleanup(configtest.SetupConfig())
|
|
})
|
|
DescribeTable("FullName",
|
|
func(enabled bool, tags Tags, expected string) {
|
|
conf.Server.Subsonic.AppendAlbumVersion = enabled
|
|
a := Album{Name: "Album", Tags: tags}
|
|
Expect(a.FullName()).To(Equal(expected))
|
|
},
|
|
Entry("appends version when enabled and tag is present", true, Tags{TagAlbumVersion: []string{"Remastered"}}, "Album (Remastered)"),
|
|
Entry("returns just name when disabled", false, Tags{TagAlbumVersion: []string{"Remastered"}}, "Album"),
|
|
Entry("returns just name when tag is absent", true, Tags{}, "Album"),
|
|
Entry("returns just name when tag is an empty slice", true, Tags{TagAlbumVersion: []string{}}, "Album"),
|
|
Entry("does not double parentheses when version is already parenthesized", true, Tags{TagAlbumVersion: []string{"(Remastered)"}}, "Album (Remastered)"),
|
|
Entry("does not add parentheses when version is wrapped in square brackets", true, Tags{TagAlbumVersion: []string{"[Remastered]"}}, "Album [Remastered]"),
|
|
)
|
|
})
|
|
|
|
var _ = Describe("Albums", func() {
|
|
var albums Albums
|
|
|
|
Context("JSON Marshalling", func() {
|
|
When("we have a valid Albums object", func() {
|
|
BeforeEach(func() {
|
|
albums = Albums{
|
|
{ID: "1", AlbumArtist: "Artist", AlbumArtistID: "11", SortAlbumArtistName: "SortAlbumArtistName", OrderAlbumArtistName: "OrderAlbumArtistName"},
|
|
{ID: "2", AlbumArtist: "Artist", AlbumArtistID: "11", SortAlbumArtistName: "SortAlbumArtistName", OrderAlbumArtistName: "OrderAlbumArtistName"},
|
|
}
|
|
})
|
|
It("marshals correctly", func() {
|
|
data, err := json.Marshal(albums)
|
|
Expect(err).To(BeNil())
|
|
|
|
var albums2 Albums
|
|
err = json.Unmarshal(data, &albums2)
|
|
Expect(err).To(BeNil())
|
|
Expect(albums2).To(Equal(albums))
|
|
})
|
|
})
|
|
})
|
|
})
|