You've already forked woodpecker
mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-06-03 16:35:37 +02:00
fix: panic due to an invalid memory address when injectSecretRecursive encounters nil values (#5699)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user