diff --git a/pkg/argocd/update.go b/pkg/argocd/update.go index 816f3fd0..143ff6db 100644 --- a/pkg/argocd/update.go +++ b/pkg/argocd/update.go @@ -492,8 +492,12 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by } func dotToObj(key string, value string) map[string]interface{} { - keys := strings.Split(key, ".") obj := make(map[string]interface{}) + if key == "" { + return obj + } + + keys := strings.Split(key, ".") current := obj for i, k := range keys { diff --git a/pkg/argocd/update_test.go b/pkg/argocd/update_test.go index 199b4436..9e3d5084 100644 --- a/pkg/argocd/update_test.go +++ b/pkg/argocd/update_test.go @@ -1652,6 +1652,28 @@ random: }) } +func Test_DotToObj(t *testing.T) { + t.Run("no value", func(t *testing.T) { + obj := dotToObj("", "val") + assert.Equal(t, map[string]interface{}{}, obj) + }) + + t.Run("single value", func(t *testing.T) { + obj := dotToObj("a", "val") + assert.Equal(t, map[string]interface{}{"a": "val"}, obj) + }) + + t.Run("multiple values", func(t *testing.T) { + obj := dotToObj("a.b.c", "val") + assert.Equal(t, map[string]interface{}{"a": map[string]interface{}{ + "b": map[string]interface{}{ + "c": "val", + }, + }, + }, obj) + }) +} + func Test_GetWriteBackConfig(t *testing.T) { t.Run("Valid write-back config - git", func(t *testing.T) { app := v1alpha1.Application{