Skip to content

Commit

Permalink
Fix: type conversion for zero values (helm#5151)
Browse files Browse the repository at this point in the history
* added test for zero values

Signed-off-by: Flavian <[email protected]>

* implemented case for zero values

Signed-off-by: Flavian <[email protected]>
  • Loading branch information
Flask authored and Matthew Fisher committed Feb 1, 2019
1 parent d3373f5 commit 69c7ba3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/strvals/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ func typedVal(v []rune, st bool) interface{} {
return nil
}

if strings.EqualFold(val, "0") {
return int64(0)
}

// If this value does not start with zero, try parsing it to an int
if len(val) != 0 && val[0] != '0' {
if iv, err := strconv.ParseInt(val, 10, 64); err == nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/strvals/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func TestParseSet(t *testing.T) {
expect: map[string]interface{}{"is_null": "null"},
err: false,
},
{
str: "zero=0",
expect: map[string]interface{}{"zero": "0"},
err: false,
},
}
tests := []struct {
str string
Expand Down Expand Up @@ -123,6 +128,10 @@ func TestParseSet(t *testing.T) {
str: "leading_zeros=00009",
expect: map[string]interface{}{"leading_zeros": "00009"},
},
{
str: "zero_int=0",
expect: map[string]interface{}{"zero_int": 0},
},
{
str: "long_int=1234567890",
expect: map[string]interface{}{"long_int": 1234567890},
Expand Down

0 comments on commit 69c7ba3

Please sign in to comment.