Error when parsing an empty key
diff --git a/keysparsing.go b/keysparsing.go index 7535379..4deed81 100644 --- a/keysparsing.go +++ b/keysparsing.go
@@ -70,6 +70,9 @@ if buffer.Len() > 0 { groups = append(groups, buffer.String()) } + if len(groups) == 0 { + return nil, fmt.Errorf("empty key") + } return groups, nil }
diff --git a/keysparsing_test.go b/keysparsing_test.go index 2d5379f..ef7e2a5 100644 --- a/keysparsing_test.go +++ b/keysparsing_test.go
@@ -42,3 +42,8 @@ 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") +}