Merge pull request #109 from olegshaldybin/fix-off-by-one

Fix off-by-one in matchLiteral
This commit is contained in:
Derek Collison
2015-08-21 21:57:17 -07:00
2 changed files with 3 additions and 2 deletions

View File

@@ -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

View File

@@ -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) {