Skip to content

Commit fa1c2ab

Browse files
committed
Error when parsing an empty key
1 parent a6c6ad1 commit fa1c2ab

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

keysparsing.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ func parseKey(key string) ([]string, error) {
7070
if buffer.Len() > 0 {
7171
groups = append(groups, buffer.String())
7272
}
73+
if len(groups) == 0 {
74+
return nil, fmt.Errorf("empty key")
75+
}
7376
return groups, nil
7477
}
7578

keysparsing_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,8 @@ func TestDottedKeyBasic(t *testing.T) {
4242
func TestBaseKeyPound(t *testing.T) {
4343
testError(t, "hello#world", "invalid bare character: #")
4444
}
45+
46+
func TestEmptyKey(t *testing.T) {
47+
testError(t, "", "empty key")
48+
testError(t, " ", "empty key")
49+
}

0 commit comments

Comments
 (0)