mirror of
https://github.com/hashicorp/vault.git
synced 2026-06-09 08:55:13 -04:00
Fix index out of range bug in ParseKeyValues
This commit is contained in:
parent
b129929422
commit
fb15c97c6c
2 changed files with 12 additions and 2 deletions
|
|
@ -69,6 +69,10 @@ func ParseKeyValues(input string, out map[string]string, sep string) error {
|
|||
|
||||
for _, keyValue := range keyValues {
|
||||
shards := strings.Split(keyValue, "=")
|
||||
if len(shards) != 2 {
|
||||
return fmt.Errorf("invalid <key,value> format")
|
||||
}
|
||||
|
||||
key := strings.TrimSpace(shards[0])
|
||||
value := strings.TrimSpace(shards[1])
|
||||
if key == "" || value == "" {
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ func TestStrutil_ParseKeyValues(t *testing.T) {
|
|||
input = "key1 = value1, key2 = "
|
||||
err = ParseKeyValues(input, actual, ",")
|
||||
if err == nil {
|
||||
t.Fatal("expected an error")
|
||||
t.Fatalf("expected an error")
|
||||
}
|
||||
for k, _ := range actual {
|
||||
delete(actual, k)
|
||||
|
|
@ -148,11 +148,17 @@ func TestStrutil_ParseKeyValues(t *testing.T) {
|
|||
input = "key1 = value1, = value2 "
|
||||
err = ParseKeyValues(input, actual, ",")
|
||||
if err == nil {
|
||||
t.Fatal("expected an error")
|
||||
t.Fatalf("expected an error")
|
||||
}
|
||||
for k, _ := range actual {
|
||||
delete(actual, k)
|
||||
}
|
||||
|
||||
input = "key1"
|
||||
err = ParseKeyValues(input, actual, ",")
|
||||
if err == nil {
|
||||
t.Fatalf("expected an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStrutil_ParseArbitraryKeyValues(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue