Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions internal/hook/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,22 @@ func GetParameter(s string, params interface{}) (interface{}, error) {
return v, nil
}

// Checked for dotted references
p := strings.SplitN(s, ".", 2)
if pValue, ok := params.(map[string]interface{})[p[0]]; ok {
if len(p) > 1 {
return GetParameter(p[1], pValue)
// Check for dotted references
p := strings.Split(s, ".")
ref := ""
for i := range p {
if i == 0 {
ref = p[i]
} else {
ref += "." + p[i]
}
if pValue, ok := params.(map[string]interface{})[ref]; ok {
if i == len(p)-1 {
return pValue, nil
} else {
return GetParameter(strings.Join(p[i+1:], "."), pValue)
}
}

return pValue, nil
}
}

Expand Down
2 changes: 2 additions & 0 deletions internal/hook/hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ var extractParameterTests = []struct {
{"b", map[string]interface{}{"b": map[string]interface{}{"z": 1}}, `{"z":1}`, true},
{"c", map[string]interface{}{"c": []interface{}{"y", "z"}}, `["y","z"]`, true},
{"d", map[string]interface{}{"d": [2]interface{}{"y", "z"}}, `["y","z"]`, true},
{"a.b.c.1", map[string]interface{}{"a": map[string]interface{}{"b": map[string]interface{}{"c.1": "z"}}}, "z", true},
{"a.b.1.c", map[string]interface{}{"a": map[string]interface{}{"b.1": map[string]interface{}{"c": "z"}}}, "z", true},
// failures
{"check_nil", nil, "", false},
{"a.X", map[string]interface{}{"a": map[string]interface{}{"b": "z"}}, "", false}, // non-existent parameter reference
Expand Down