From 1850aeade9efe7edb960b130daa46c727ad98bab Mon Sep 17 00:00:00 2001 From: Michelle Noorali Date: Tue, 17 Apr 2018 15:04:53 -0400 Subject: [PATCH] fix(pkg/strvals): evaluate "null" values resolves #3891 Co-authored-by: Matthew Fisher --- pkg/strvals/parser.go | 8 ++++++++ pkg/strvals/parser_test.go | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/pkg/strvals/parser.go b/pkg/strvals/parser.go index aa3d15904..8d20c3bc3 100644 --- a/pkg/strvals/parser.go +++ b/pkg/strvals/parser.go @@ -82,6 +82,10 @@ func ParseIntoString(s string, dest map[string]interface{}) error { // parser is a simple parser that takes a strvals line and parses it into a // map representation. +// +// where sc is the source of the original data being parsed +// where data is the final parsed data from the parses with correct types +// where st is a boolean to figure out if we're forcing it to parse values as string type parser struct { sc *bytes.Buffer data map[string]interface{} @@ -329,6 +333,10 @@ func typedVal(v []rune, st bool) interface{} { return false } + if strings.EqualFold(val, "null") { + 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 iv, err := strconv.ParseInt(val, 10, 64); err == nil { diff --git a/pkg/strvals/parser_test.go b/pkg/strvals/parser_test.go index fd287bf8a..482377c32 100644 --- a/pkg/strvals/parser_test.go +++ b/pkg/strvals/parser_test.go @@ -81,6 +81,11 @@ func TestParseSet(t *testing.T) { expect map[string]interface{} err bool }{ + { + "name1=null,f=false,t=true", + map[string]interface{}{"name1": nil, "f": false, "t": true}, + false, + }, { "name1=value1", map[string]interface{}{"name1": "value1"},