From c6f9cc72dcff46dc2de4990be1bf382876da35d5 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Wed, 29 Jul 2026 20:23:30 +0200 Subject: [PATCH] refactor(search): harden the index-diff helpers against unset input --- services/search/pkg/opensearch/index.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/services/search/pkg/opensearch/index.go b/services/search/pkg/opensearch/index.go index cf3f6edd98..e8bbe4f066 100644 --- a/services/search/pkg/opensearch/index.go +++ b/services/search/pkg/opensearch/index.go @@ -207,7 +207,14 @@ func (m IndexManager) Apply(ctx context.Context, name string, client *opensearch return nil } +// jsonEqual reports whether two raw JSON values are deeply equal. gjson yields +// an empty string for a path that does not exist; two such unset values are +// equal, an unset value never equals a present one, and a value that fails to +// parse counts as unequal. func jsonEqual(a, b string) bool { + if a == "" || b == "" { + return a == b + } var av, bv any if err := json.Unmarshal([]byte(a), &av); err != nil { return false @@ -218,11 +225,14 @@ func jsonEqual(a, b string) bool { return reflect.DeepEqual(av, bv) } -// propertiesMap parses a raw mappings.properties object; missing or empty -// input yields an empty map, which classifies as purely additive. +// propertiesMap parses a raw mappings.properties object into a map. Missing, +// empty, null or malformed input yields an empty (non-nil) map, which +// classifies as purely additive. func propertiesMap(raw string) map[string]any { props := map[string]any{} - _ = json.Unmarshal([]byte(raw), &props) + if err := json.Unmarshal([]byte(raw), &props); err != nil || props == nil { + return map[string]any{} + } return props }