From 609e72b357c8be43c3ec5f2d148f2188233ef0b1 Mon Sep 17 00:00:00 2001 From: Sam Leavens Date: Wed, 26 Jul 2017 17:16:39 -0700 Subject: [PATCH 1/2] fix(pkg/strvals): preserve leading zeros in vals When passing values with "helm install --set" values with leading zeros are preserved and not parsed as ints. Closes #2693 --- pkg/strvals/parser.go | 7 +++++-- pkg/strvals/parser_test.go | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/strvals/parser.go b/pkg/strvals/parser.go index 842f36c24..b945b0a34 100644 --- a/pkg/strvals/parser.go +++ b/pkg/strvals/parser.go @@ -308,8 +308,11 @@ func typedVal(v []rune) interface{} { return false } - if iv, err := strconv.ParseInt(val, 10, 64); err == nil { - return iv + // If this value does not start with zero, try parsing it to an int + if len(val) != 0 && val[0] != 48 { + if iv, err := strconv.ParseInt(val, 10, 64); err == nil { + return iv + } } return val diff --git a/pkg/strvals/parser_test.go b/pkg/strvals/parser_test.go index 061de0a13..a3f6e4207 100644 --- a/pkg/strvals/parser_test.go +++ b/pkg/strvals/parser_test.go @@ -93,6 +93,10 @@ func TestParseSet(t *testing.T) { str: "name1=,name2=value2", expect: map[string]interface{}{"name1": "", "name2": "value2"}, }, + { + str: "leading_zeros=00009", + expect: map[string]interface{}{"leading_zeros": "00009"}, + }, { str: "name1,name2=", err: true, From a5dc546726e664db822104cb612fb74a4a134df0 Mon Sep 17 00:00:00 2001 From: Sam Leavens Date: Thu, 27 Jul 2017 11:29:51 -0700 Subject: [PATCH 2/2] fix(pkg/strvals): use rune literal instead of ASCII When checking that a value begins with zero use a rune literal instead of the ASCII code for zero. --- pkg/strvals/parser.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/strvals/parser.go b/pkg/strvals/parser.go index b945b0a34..8e97b4d44 100644 --- a/pkg/strvals/parser.go +++ b/pkg/strvals/parser.go @@ -309,7 +309,7 @@ func typedVal(v []rune) interface{} { } // If this value does not start with zero, try parsing it to an int - if len(val) != 0 && val[0] != 48 { + if len(val) != 0 && val[0] != '0' { if iv, err := strconv.ParseInt(val, 10, 64); err == nil { return iv }