@@ -66,7 +66,13 @@ func (eh *EventHistory) scan(key string, recursive bool, index uint64) (*Event,
ok := (e.Key == key)
if recursive {
- ok = ok || strings.HasPrefix(e.Key, path.Join(key, "/"))
+ // add tailing slash
+ key := path.Clean(key)
+ if key[len(key)-1] != '/' {
+ key = key + "/"
+ }
+
+ ok = ok || strings.HasPrefix(e.Key, key)
}
if ok && index <= e.Index() { // make sure we bypass the smaller one
@@ -68,4 +68,24 @@ func TestWatcher(t *testing.T) {
t.Fatal("recv != send")
+ // ensure we are doing exact matching rather than prefix matching
+ c, _ = wh.watch("/fo", true, 1)
+ select {
+ case re = <-c:
+ t.Fatal("should not receive from channel:", re)
+ default:
+ // do nothing
+ e = newEvent(Create, "/fo/bar", 3)
+ wh.notify(e)
+ re = <-c
+ if e != re {
+ t.Fatal("recv != send")