mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-17 03:24:40 -07:00
Merge pull request #109 from olegshaldybin/fix-off-by-one
Fix off-by-one in matchLiteral
This commit is contained in:
@@ -193,7 +193,6 @@ func (s *Sublist) removeFromCache(subject []byte, sub interface{}) {
|
||||
// slice of results.
|
||||
func (s *Sublist) Match(subject []byte) []interface{} {
|
||||
// Fastpath match on cache
|
||||
|
||||
s.mu.RLock()
|
||||
atomic.AddUint64(&s.stats.matches, 1)
|
||||
r := s.cache.Get(subject)
|
||||
@@ -426,7 +425,7 @@ func matchLiteral(literal, subject []byte) bool {
|
||||
li += 1
|
||||
}
|
||||
// Make sure we have processed all of the literal's chars..
|
||||
if li < (ll - 1) {
|
||||
if li < ll {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -250,6 +250,8 @@ func TestMatchLiterals(t *testing.T) {
|
||||
checkBool(matchLiteral([]byte("stats.test.22"), []byte("stats.>")), true, t)
|
||||
checkBool(matchLiteral([]byte("stats.test.22"), []byte("stats.*.*")), true, t)
|
||||
checkBool(matchLiteral([]byte("foo.bar"), []byte("foo")), false, t)
|
||||
checkBool(matchLiteral([]byte("stats.test.foos"), []byte("stats.test.foos")), true, t)
|
||||
checkBool(matchLiteral([]byte("stats.test.foos"), []byte("stats.test.foo")), false, t)
|
||||
}
|
||||
|
||||
func TestCacheBounds(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user