helper/variables: trim whitespace on key before empty string comp

This commit is contained in:
Mitchell Hashimoto 2016-12-14 13:52:34 -08:00
parent b7f6f8eb2a
commit 6d594b3bc6
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 9 additions and 3 deletions

View File

@ -21,6 +21,9 @@ func (v *Flag) Set(raw string) error {
} }
key, input := raw[0:idx], raw[idx+1:] key, input := raw[0:idx], raw[idx+1:]
// Trim the whitespace on the key
key = strings.TrimSpace(key)
if key == "" { if key == "" {
return fmt.Errorf("No key to left '=' in arg: %s", raw) return fmt.Errorf("No key to left '=' in arg: %s", raw)
} }
@ -30,9 +33,6 @@ func (v *Flag) Set(raw string) error {
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
} }

View File

@ -25,6 +25,12 @@ func TestFlag(t *testing.T) {
true, true,
}, },
{
" =value",
nil,
true,
},
{ {
"key=value", "key=value",
map[string]interface{}{"key": "value"}, map[string]interface{}{"key": "value"},