Skip to content

Commit 95e3034

Browse files
authored
fix: add missing normalize calls to keys in various areas (#2)
1 parent 2383bc5 commit 95e3034

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

etcd.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (s *Store) Put(ctx context.Context, key string, value []byte, opts *store.W
104104
pr := s.client.Txn(ctxTxn)
105105

106106
if opts == nil || opts.TTL <= 0 {
107-
pr.Then(etcd.OpPut(key, string(value)))
107+
pr.Then(etcd.OpPut(normalize(key), string(value)))
108108

109109
_, err := pr.Commit()
110110
if err != nil {
@@ -134,7 +134,7 @@ func (s *Store) Put(ctx context.Context, key string, value []byte, opts *store.W
134134
}()
135135
}
136136

137-
pr.Then(etcd.OpPut(key, string(value), etcd.WithLease(grant.ID)))
137+
pr.Then(etcd.OpPut(normalize(key), string(value), etcd.WithLease(grant.ID)))
138138

139139
_, err = pr.Commit()
140140
if err != nil {
@@ -275,11 +275,11 @@ func (s *Store) AtomicPut(ctx context.Context, key string, value []byte, previou
275275
if previous != nil {
276276
// We compare on the last modified index.
277277
testIndex = true
278-
cmp = etcd.Compare(etcd.ModRevision(key), "=", int64(previous.LastIndex))
278+
cmp = etcd.Compare(etcd.ModRevision(normalize(key)), "=", int64(previous.LastIndex))
279279
} else {
280280
// Previous key is not given, thus we want the key not to exist.
281281
testIndex = false
282-
cmp = etcd.Compare(etcd.CreateRevision(key), "=", 0)
282+
cmp = etcd.Compare(etcd.CreateRevision(normalize(key)), "=", 0)
283283
}
284284

285285
ctx, cancel := context.WithTimeout(ctx, etcdDefaultTimeout)
@@ -294,9 +294,9 @@ func (s *Store) AtomicPut(ctx context.Context, key string, value []byte, previou
294294
if err != nil {
295295
return false, nil, err
296296
}
297-
pr.Then(etcd.OpPut(key, string(value), etcd.WithLease(resp.ID)))
297+
pr.Then(etcd.OpPut(normalize(key), string(value), etcd.WithLease(resp.ID)))
298298
} else {
299-
pr.Then(etcd.OpPut(key, string(value)))
299+
pr.Then(etcd.OpPut(normalize(key), string(value)))
300300
}
301301

302302
txn, err := pr.Commit()
@@ -312,7 +312,7 @@ func (s *Store) AtomicPut(ctx context.Context, key string, value []byte, previou
312312
}
313313

314314
updated := &store.KVPair{
315-
Key: key,
315+
Key: normalize(key),
316316
Value: value,
317317
LastIndex: uint64(txn.Header.Revision),
318318
}
@@ -328,14 +328,14 @@ func (s *Store) AtomicDelete(ctx context.Context, key string, previous *store.KV
328328
}
329329

330330
// We compare on the last modified index.
331-
cmp := etcd.Compare(etcd.ModRevision(key), "=", int64(previous.LastIndex))
331+
cmp := etcd.Compare(etcd.ModRevision(normalize(key)), "=", int64(previous.LastIndex))
332332

333333
ctx, cancel := context.WithTimeout(ctx, etcdDefaultTimeout)
334334
defer cancel()
335335

336336
txn, err := s.client.Txn(ctx).
337337
If(cmp).
338-
Then(etcd.OpDelete(key)).
338+
Then(etcd.OpDelete(normalize(key))).
339339
Commit()
340340
if err != nil {
341341
return false, err

0 commit comments

Comments
 (0)