Error when parsing an empty key

This commit is contained in:
Thomas Pelletier
2015-12-01 14:02:02 +01:00
parent a6c6ad1f5f
commit fa1c2ab68c
2 changed files with 8 additions and 0 deletions
+3
View File
@@ -70,6 +70,9 @@ func parseKey(key string) ([]string, error) {
if buffer.Len() > 0 {
groups = append(groups, buffer.String())
}
if len(groups) == 0 {
return nil, fmt.Errorf("empty key")
}
return groups, nil
}
+5
View File
@@ -42,3 +42,8 @@ func TestDottedKeyBasic(t *testing.T) {
func TestBaseKeyPound(t *testing.T) {
testError(t, "hello#world", "invalid bare character: #")
}
func TestEmptyKey(t *testing.T) {
testError(t, "", "empty key")
testError(t, " ", "empty key")
}