Merge pull request #834 from apoydence/master
Returns an error for a key with a '/'
This commit is contained in:
commit
4d8b4abcc5
|
@ -168,6 +168,10 @@ func (k *KV) Release(p *KVPair, q *WriteOptions) (bool, *WriteMeta, error) {
|
|||
}
|
||||
|
||||
func (k *KV) put(key string, params map[string]string, body []byte, q *WriteOptions) (bool, *WriteMeta, error) {
|
||||
if len(key) > 0 && key[0] == '/' {
|
||||
return false, nil, fmt.Errorf("Invalid key. Key must not begin with a '/': %s", key)
|
||||
}
|
||||
|
||||
r := k.c.newRequest("PUT", "/v1/kv/"+key)
|
||||
r.setWriteOptions(q)
|
||||
for param, val := range params {
|
||||
|
|
|
@ -31,6 +31,14 @@ func TestClientPutGetDelete(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Put a key that begins with a '/'
|
||||
invalidKey := "/test"
|
||||
value = []byte(invalidKey)
|
||||
p = &KVPair{Key: key, Flags: 42, Value: value}
|
||||
if _, err := kv.Put(p, nil); err == nil {
|
||||
t.Fatalf("Invalid key not detected: %s", invalidKey)
|
||||
}
|
||||
|
||||
// Get should work
|
||||
pair, meta, err := kv.Get(key, nil)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue