diff --git a/helper/variables/flag.go b/helper/variables/flag.go index 393586234..3af1d9164 100644 --- a/helper/variables/flag.go +++ b/helper/variables/flag.go @@ -21,6 +21,13 @@ func (v *Flag) Set(raw string) error { } key, input := raw[0:idx], raw[idx+1:] + + // Trim the whitespace on the key + key = strings.TrimSpace(key) + if key == "" { + return fmt.Errorf("No key to left '=' in arg: %s", raw) + } + value, err := ParseInput(input) if err != nil { return err diff --git a/helper/variables/flag_test.go b/helper/variables/flag_test.go index f88b42cd1..1bd5471ae 100644 --- a/helper/variables/flag_test.go +++ b/helper/variables/flag_test.go @@ -19,6 +19,18 @@ func TestFlag(t *testing.T) { Output map[string]interface{} Error bool }{ + { + "=value", + nil, + true, + }, + + { + " =value", + nil, + true, + }, + { "key=value", map[string]interface{}{"key": "value"}, @@ -43,6 +55,24 @@ func TestFlag(t *testing.T) { false, }, + { + "key =value", + map[string]interface{}{"key": "value"}, + false, + }, + + { + "key = value", + map[string]interface{}{"key": " value"}, + false, + }, + + { + `key = "value"`, + map[string]interface{}{"key": "value"}, + false, + }, + { "map.key=foo", map[string]interface{}{"map.key": "foo"},