From 818603436cbbedcefb11820cb2c245c03c944d42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alen=20Po=C5=BEun?= Date: Tue, 10 Nov 2026 15:26:16 +0100 Subject: [PATCH] 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 Co-authored-by: Deluan --- model/criteria/criteria_test.go | 12 ++++++++++++ model/criteria/json.go | 12 +++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/model/criteria/criteria_test.go b/model/criteria/criteria_test.go index de5124568..5a8ebaa5c 100644 --- a/model/criteria/criteria_test.go +++ b/model/criteria/criteria_test.go @@ -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":[]}]}`), + ) }) diff --git a/model/criteria/json.go b/model/criteria/json.go index d0f453524..87f768298 100644 --- a/model/criteria/json.go +++ b/model/criteria/json.go @@ -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}) }