helper/variables: trim whitespace around the key in -var
Fixes #10716 This trims whitespace around the key in the `-var` flag. This is a regression from 0.7.x. The value is whitespace sensitive unless double-quoted. This is the same behavior as 0.7.x. I considered rejecting whitespace around the '=' completely but I don't want to introduce BC and the behavior actually seems quite obvious to me.
This commit is contained in:
parent
014b414839
commit
b7f6f8eb2a
|
@ -21,11 +21,18 @@ func (v *Flag) Set(raw string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
key, input := raw[0:idx], raw[idx+1:]
|
key, input := raw[0:idx], raw[idx+1:]
|
||||||
|
if key == "" {
|
||||||
|
return fmt.Errorf("No key to left '=' in arg: %s", raw)
|
||||||
|
}
|
||||||
|
|
||||||
value, err := ParseInput(input)
|
value, err := ParseInput(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trim the whitespace on the key
|
||||||
|
key = strings.TrimSpace(key)
|
||||||
|
|
||||||
*v = Merge(*v, map[string]interface{}{key: value})
|
*v = Merge(*v, map[string]interface{}{key: value})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,12 @@ func TestFlag(t *testing.T) {
|
||||||
Output map[string]interface{}
|
Output map[string]interface{}
|
||||||
Error bool
|
Error bool
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
"=value",
|
||||||
|
nil,
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"key=value",
|
"key=value",
|
||||||
map[string]interface{}{"key": "value"},
|
map[string]interface{}{"key": "value"},
|
||||||
|
@ -43,6 +49,24 @@ func TestFlag(t *testing.T) {
|
||||||
false,
|
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.key=foo",
|
||||||
map[string]interface{}{"map.key": "foo"},
|
map[string]interface{}{"map.key": "foo"},
|
||||||
|
|
Loading…
Reference in New Issue