From ef00a1ec1e65d9643392bea907089c22e2bae386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Thu, 22 Feb 2024 17:24:48 +0800 Subject: [PATCH] Fix badjson merge --- common/json/badjson/merge.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/json/badjson/merge.go b/common/json/badjson/merge.go index 61b5f4c..35e9494 100644 --- a/common/json/badjson/merge.go +++ b/common/json/badjson/merge.go @@ -93,6 +93,11 @@ func MergeJSON(rawSource json.RawMessage, rawDestination json.RawMessage) (json. if err != nil { return nil, E.Cause(err, "decode destination") } + if source == nil { + return json.Marshal(destination) + } else if destination == nil { + return json.Marshal(source) + } merged, err := mergeJSON(source, destination) if err != nil { return nil, err @@ -125,7 +130,7 @@ func mergeJSON(anySource any, anyDestination any) (any, error) { destination.Put(entry.Key, entry.Value) } default: - return nil, E.New("cannot merge json object into ", reflect.TypeOf(destination)) + return nil, E.New("cannot merge json object into ", reflect.TypeOf(source)) } return destination, nil default: