diff --git a/pipeline/frontend/yaml/compiler/settings/params.go b/pipeline/frontend/yaml/compiler/settings/params.go index c9d61ee115..4196ccbec5 100644 --- a/pipeline/frontend/yaml/compiler/settings/params.go +++ b/pipeline/frontend/yaml/compiler/settings/params.go @@ -194,7 +194,9 @@ func injectSecret(v map[string]any, getSecretValue func(name string) (string, er // it iterates recursively over them too, using injectSecret internally. func injectSecretRecursive(v any, getSecretValue func(name string) (string, error)) (any, error) { t := reflect.TypeOf(v) - + if t == nil { + return v, nil + } if !isComplex(t.Kind()) { return v, nil } diff --git a/pipeline/frontend/yaml/compiler/settings/params_test.go b/pipeline/frontend/yaml/compiler/settings/params_test.go index 44cce18203..43238d4630 100644 --- a/pipeline/frontend/yaml/compiler/settings/params_test.go +++ b/pipeline/frontend/yaml/compiler/settings/params_test.go @@ -304,3 +304,21 @@ func TestSecretMappingComplexMapWithSecrets(t *testing.T) { assert.Equal(t, expectedJSON, secretMapping["PLUGIN_CONFIG"]) assert.NotContains(t, secretMapping, "PLUGIN_SIMPLE_VAR") } + +func TestComplexTypesWithNilValuesWontPanic(t *testing.T) { + from := map[string]any{ + "config": []any{ + "copy a b", + map[string]any{ + "foo": nil, + }, + }, + } + + got := map[string]string{} + expectedJSON := `["copy a b",{"foo":null}]` + + err := ParamsToEnv(from, got, "PLUGIN_", true, nil, nil) + assert.NoError(t, err) + assert.Equal(t, expectedJSON, got["PLUGIN_CONFIG"]) +}