Skip to content

Commit

Permalink
Merge pull request #1223 from dev-drprasad/bool-flag-cause-panic
Browse files Browse the repository at this point in the history
🐛 Fix non-string yaml keys of flags causing panic
  • Loading branch information
carolynvs authored Aug 26, 2020
2 parents 78b5062 + 06cc2e8 commit e0c1d5e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/exec/builder/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (flags *Flags) ToSlice(dashes Dashes) []string {
//
// []Flags{ {"flag1", []string{"value"}}, {"flag2", []string{"value"}}, {"flag3", []string{"value1", "value2"} }
func (flags *Flags) UnmarshalYAML(unmarshal func(interface{}) error) error {
flagMap := map[interface{}]interface{}{}
flagMap := map[string]interface{}{}
err := unmarshal(&flagMap)
if err != nil {
return errors.Wrap(err, "could not unmarshal yaml into Step.Flags")
Expand All @@ -86,7 +86,7 @@ func (flags *Flags) UnmarshalYAML(unmarshal func(interface{}) error) error {
*flags = make(Flags, 0, len(flagMap))
for k, v := range flagMap {
f := Flag{}
f.Name = k.(string)
f.Name = k

switch t := v.(type) {
case []interface{}:
Expand Down
13 changes: 13 additions & 0 deletions pkg/exec/builder/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,16 @@ func TestFlags_ToSlice(t *testing.T) {
// Flags should be sorted and sliced up on a platter
assert.Equal(t, []string{"-a", "1", "--bull", "2"}, args)
}

func TestFlags_NonStringKeys(t *testing.T) {
flags := Flags{}
err := yaml.Unmarshal([]byte(`
yes: ["y", "true"]
true: ["y", "yes"]
nil: ["no", "nah"]
1.0: ["true", "yes"]
1: ["yes"]
`), &flags)
assert.NoError(t, err)
assert.Equal(t, 5, len(flags))
}

0 comments on commit e0c1d5e

Please sign in to comment.