From 0354991b92587e2742549d3036f3b5bae5ab03f2 Mon Sep 17 00:00:00 2001 From: gobwas Date: Sun, 23 Oct 2016 00:02:45 +0300 Subject: [PATCH] bugfix with row length --- glob_test.go | 4 ++++ match/row.go | 14 +++----------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/glob_test.go b/glob_test.go index 071ccb3..86ccbe9 100644 --- a/glob_test.go +++ b/glob_test.go @@ -105,6 +105,10 @@ func TestGlob(t *testing.T) { glob(true, "???", "abc"), glob(true, "?*?", "abc"), glob(true, "?*?", "ac"), + glob(false, "sta", "stagnation"), + glob(true, "sta*", "stagnation"), + glob(false, "sta?", "stagnation"), + glob(false, "sta?n", "stagnation"), glob(true, "{abc,def}ghi", "defghi"), glob(true, "{abc,abcd}a", "abcda"), diff --git a/match/row.go b/match/row.go index 820a60d..0b9754d 100644 --- a/match/row.go +++ b/match/row.go @@ -45,12 +45,11 @@ func (self Row) lenOk(s string) bool { var i int for _ = range s { i++ - if i >= self.RunesLength { - return true + if i > self.RunesLength { + return false } } - - return false + return self.RunesLength == i } func (self Row) Match(s string) bool { @@ -62,21 +61,14 @@ func (self Row) Len() (l int) { } func (self Row) Index(s string) (int, []int) { - if !self.lenOk(s) { - return -1, nil - } - for i := range s { - // this is not strict check but useful if len(s[i:]) < self.RunesLength { break } - if self.matchAll(s[i:]) { return i, self.Segments } } - return -1, nil }