refactor: broke boolean expression into functions that protect against cast panics

Signed-off-by: Jesse Simpson <jesse.simpson@camunda.com>
pull/12812/head
Jesse Simpson 2 years ago committed by Jesse Simpson
parent 415e3ce9db
commit 34cfd617dc
No known key found for this signature in database
GPG Key ID: 237495C89AB0AAFC

@ -300,7 +300,7 @@ func coalesceTablesFullKey(printf printFn, dst, src map[string]interface{}, pref
} else { } else {
printf("warning: cannot overwrite table with non table for %s (%v)", fullkey, val) printf("warning: cannot overwrite table with non table for %s (%v)", fullkey, val)
} }
} else if istable(dv) && val != nil && val != "" && len(dv.(map[string]interface{})) > 0 { } else if istable(dv) && val != nil && isNonEmptyString(val) && isNonEmptyTable(dv) {
printf("warning: destination for %s is a table. Ignoring non-table value (%v)", fullkey, val) printf("warning: destination for %s is a table. Ignoring non-table value (%v)", fullkey, val)
} }
} }

@ -179,6 +179,24 @@ func istable(v interface{}) bool {
return ok return ok
} }
func isNonEmptyTable(val interface{}) bool {
table, ok := val.(map[string]interface{})
if !ok {
return false
}
return len(table) > 0
}
func isNonEmptyString(val interface{}) bool {
stringContent, ok := val.(string)
if !ok {
return false
}
return stringContent != ""
}
// PathValue takes a path that traverses a YAML structure and returns the value at the end of that path. // PathValue takes a path that traverses a YAML structure and returns the value at the end of that path.
// The path starts at the root of the YAML structure and is comprised of YAML keys separated by periods. // The path starts at the root of the YAML structure and is comprised of YAML keys separated by periods.
// Given the following YAML data the value at path "chapter.one.title" is "Loomings". // Given the following YAML data the value at path "chapter.one.title" is "Loomings".

Loading…
Cancel
Save