Commit 239155b9 authored by Gari Singh's avatar Gari Singh Committed by Gerrit Code Review
Browse files

Merge "Fix for an empty string as a couchdb key"

parents 4c7ffa33 571bdef8
......@@ -216,6 +216,9 @@ func validateKey(key string) error {
if strings.HasPrefix(key, "_") {
return errors.Errorf("invalid key [%s], cannot begin with \"_\"", key)
}
if key == "" {
return errors.New("invalid key. Empty string is not supported as a key by couchdb")
}
return nil
}
......
......@@ -160,10 +160,14 @@ func TestUtilityFunctions(t *testing.T) {
err = db.ValidateKeyValue("testKey", []byte("Some random bytes"))
assert.Nil(t, err)
// ValidateKey should return an error for an invalid key
// ValidateKeyValue should return an error for a key that is not a utf-8 valid string
err = db.ValidateKeyValue(string([]byte{0xff, 0xfe, 0xfd}), []byte("Some random bytes"))
assert.Error(t, err, "ValidateKey should have thrown an error for an invalid utf-8 string")
// ValidateKeyValue should return an error for a key that is an empty string
assert.EqualError(t, db.ValidateKeyValue("", []byte("validValue")),
"invalid key. Empty string is not supported as a key by couchdb")
reservedFields := []string{"~version", "_id", "_test"}
// ValidateKeyValue should return an error for a json value that contains one of the reserved fields
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment