From 272d9bc6efff112b578e48334054534290d3af95 Mon Sep 17 00:00:00 2001 From: Elmar Ritsch Date: Tue, 29 May 2018 21:17:37 +0200 Subject: [PATCH 1/3] Parse booleans and null as string values with --set-string flag --- pkg/strvals/parser.go | 9 +++++++-- pkg/strvals/parser_test.go | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/strvals/parser.go b/pkg/strvals/parser.go index 90670a4dd..dae949d8e 100644 --- a/pkg/strvals/parser.go +++ b/pkg/strvals/parser.go @@ -325,6 +325,11 @@ func inMap(k rune, m map[rune]bool) bool { func typedVal(v []rune, st bool) interface{} { val := string(v) + + if st { + return val + } + if strings.EqualFold(val, "true") { return true } @@ -337,8 +342,8 @@ func typedVal(v []rune, st bool) interface{} { return nil } - // If this value does not start with zero, and not returnString, try parsing it to an int - if !st && len(val) != 0 && val[0] != '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 { return iv } diff --git a/pkg/strvals/parser_test.go b/pkg/strvals/parser_test.go index c897cf0a7..54a95e6e0 100644 --- a/pkg/strvals/parser_test.go +++ b/pkg/strvals/parser_test.go @@ -75,6 +75,11 @@ func TestParseSet(t *testing.T) { expect: map[string]interface{}{"long_int_string": "1234567890"}, err: false, }, + { + str: "boolean=true", + expect: map[string]interface{}{"boolean": "true"}, + err: false, + }, } tests := []struct { str string @@ -117,6 +122,10 @@ func TestParseSet(t *testing.T) { str: "long_int=1234567890", expect: map[string]interface{}{"long_int": 1234567890}, }, + { + str: "boolean=true", + expect: map[string]interface{}{"boolean": true}, + }, { str: "name1,name2=", err: true, From 7308e766e2633bbe08f0c441e9a84a46acca38f9 Mon Sep 17 00:00:00 2001 From: Elmar Ritsch Date: Tue, 29 May 2018 21:38:21 +0200 Subject: [PATCH 2/3] Add test to make sure --set-string flag takes `null` as string --- pkg/strvals/parser_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/strvals/parser_test.go b/pkg/strvals/parser_test.go index 54a95e6e0..7ad31aa56 100644 --- a/pkg/strvals/parser_test.go +++ b/pkg/strvals/parser_test.go @@ -80,6 +80,11 @@ func TestParseSet(t *testing.T) { expect: map[string]interface{}{"boolean": "true"}, err: false, }, + { + str: "is_null=null", + expect: map[string]interface{}{"is_null": "null"}, + err: false, + }, } tests := []struct { str string From a7362d76bc6002140a153daa4ab68b87b509af89 Mon Sep 17 00:00:00 2001 From: Elmar Ritsch Date: Tue, 29 May 2018 22:06:00 +0200 Subject: [PATCH 3/3] Add test to make sure --set flag interprets `null` as `nil` --- pkg/strvals/parser_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/strvals/parser_test.go b/pkg/strvals/parser_test.go index 7ad31aa56..f6e35c81b 100644 --- a/pkg/strvals/parser_test.go +++ b/pkg/strvals/parser_test.go @@ -131,6 +131,11 @@ func TestParseSet(t *testing.T) { str: "boolean=true", expect: map[string]interface{}{"boolean": true}, }, + { + str: "is_null=null", + expect: map[string]interface{}{"is_null": nil}, + err: false, + }, { str: "name1,name2=", err: true,