Skip to content

Commit

Permalink
fix(parser): yaml parser panics on templated files (#3531)
Browse files Browse the repository at this point in the history
closes #3529
  • Loading branch information
rogeriopeixotocx authored Jun 7, 2021
1 parent 21ba4c8 commit 1b99a4b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/parser/yaml/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func convert(value interface{}) interface{} {
case map[interface{}]interface{}:
mapStr := map[string]interface{}{}
for key, val := range t {
mapStr[key.(string)] = convert(val)
if t, ok := key.(string); ok {
mapStr[t] = convert(val)
}
}
return mapStr
case []interface{}:
Expand Down
18 changes: 18 additions & 0 deletions pkg/parser/yaml/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ test:
test_2:
perm:
- <<: *test_anchor
`, `
kube_node_ready_controller_memory: "200Mi"
{{if eq .Cluster.Environment "test"}}
downscaler_default_uptime: "Mon-Fri 07:30-20:30 Europe/Berlin"
downscaler_default_downtime: "never"
downscaler_enabled: "true"
{{else if eq .Cluster.Environment "e2e"}}
downscaler_default_uptime: "always"
downscaler_default_downtime: "never"
downscaler_enabled: "true"
{{else}}
downscaler_default_uptime: "always"
downscaler_default_downtime: "never"
downscaler_enabled: "false"
{{end}}
`,
}

Expand All @@ -69,6 +84,9 @@ test_2:
require.Contains(t, nestedMap[0], "test_2")
require.Contains(t,
nestedMap[0]["test_2"].(model.Document)["perm"].([]interface{})[0].(map[string]interface{})["group"].(model.Document)["name"], "cx")

_, err = p.Parse("test.yaml", []byte(have[3]))
require.Error(t, err)
}

// Test_Resolve tests the functions [Resolve()] and all the methods called by them
Expand Down

0 comments on commit 1b99a4b

Please sign in to comment.