mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-19 15:23:36 +00:00
fix(smartplaylists): preserve empty nested groups in smart playlist criteria marshaling (#6438)
* fix: preserve empty nested groups in smart playlist criteria marshaling Fixes #6316 Empty nested groups were serialized incorrectly because of omitempty. Now only the active conjunction key is emitted, so empty groups become []. * docs: add changelog entry for #6316 * fix: recover playlists previously saved with empty nested groups Treats the old broken {} form as an empty All on unmarshal so existing playlists load again. * docs: mention recovery of previously broken playlists in changelog * style: run gofmt * fix: safer recovery of empty groups and nil slices - only treat {} as empty All when the group has no other rules - marshal nil slices as [] instead of null - drop CHANGELOG.md (release notes are generated from commits) * test: remove hand-built criteria test * test: add Ginkgo round-trip specs for empty nested groups * chore: remove CHANGELOG.md * docs: add docstrings to criteria json helpers * Revert "docs: add docstrings to criteria json helpers" This reverts commit 9f74c604a1afe88da6bde88b5fb15fb94c0bba43. * docs: add docstrings to criteria json helpers * test: fix criteria round-trip specs to use Criteria and gomega * fix(criteria): keep only the marshal fix for empty nested groups Remove the recovery that turned a group made only of {} elements into an empty All. It lived in the parser shared by POST bodies, .nsp files and scrobble filters, so it accepted inputs such as {"all":[{}]} that were rejected before, and turned them into rules that match the whole library. It also had to guess whether a saved {} was an empty all or an empty any. Rows already saved broken are a one-time cleanup, not something the parser should carry. Also remove the {}/null short-circuit (null was already handled, and {} only widened what the parser accepts), drop the doc comments that restated function names, and fold the round-trip specs into one table that checks the exact marshaled output for empty nested all and any groups. --------- Co-authored-by: kukirin-ui <kukirin-ui@users.noreply.github.com> Co-authored-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
93cead9b16
commit
818603436c
@ -423,4 +423,16 @@ var _ = Describe("Criteria", func() {
|
||||
gomega.Expect(ids).To(gomega.Equal([]string{sharedID}))
|
||||
})
|
||||
})
|
||||
|
||||
DescribeTable("empty nested groups",
|
||||
func(input, expected string) {
|
||||
var c Criteria
|
||||
gomega.Expect(json.Unmarshal([]byte(input), &c)).To(gomega.Succeed())
|
||||
out, err := json.Marshal(c)
|
||||
gomega.Expect(err).ToNot(gomega.HaveOccurred())
|
||||
gomega.Expect(string(out)).To(gomega.Equal(expected))
|
||||
},
|
||||
Entry("keeps a nested empty group", `{"all":[{"all":[]}]}`, `{"all":[{"all":[]}]}`),
|
||||
Entry("keeps a nested empty any group", `{"all":[{"any":[]}]}`, `{"all":[{"any":[]}]}`),
|
||||
)
|
||||
})
|
||||
|
||||
@ -174,14 +174,8 @@ func marshalExpression(name string, value map[string]any) ([]byte, error) {
|
||||
}
|
||||
|
||||
func marshalConjunction(name string, conj []Expression) ([]byte, error) {
|
||||
aux := struct {
|
||||
All []Expression `json:"all,omitempty"`
|
||||
Any []Expression `json:"any,omitempty"`
|
||||
}{}
|
||||
if name == "any" {
|
||||
aux.Any = conj
|
||||
} else {
|
||||
aux.All = conj
|
||||
if conj == nil {
|
||||
conj = []Expression{}
|
||||
}
|
||||
return json.Marshal(aux)
|
||||
return json.Marshal(map[string][]Expression{name: conj})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user