Merge pull request #10717 from hashicorp/b-var-whitespace

helper/variables: trim whitespace around the key in -var
This commit is contained in:
Mitchell Hashimoto 2016-12-14 13:55:22 -08:00 committed by GitHub
commit 2cf99b2556
2 changed files with 37 additions and 0 deletions

View File

@ -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

View File

@ -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"},