From 5b52bb1509df7be12737c867f43bddb8f99e2288 Mon Sep 17 00:00:00 2001 From: Dmitry Panov Date: Thu, 6 Aug 2020 17:27:06 +0100 Subject: [PATCH 1/2] Simplified getRunes() --- regexp.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/regexp.go b/regexp.go index 709e034..fba1e33 100644 --- a/regexp.go +++ b/regexp.go @@ -239,13 +239,7 @@ func (re *Regexp) getRunesAndStart(s string, startAt int) ([]rune, int) { } func getRunes(s string) []rune { - ret := make([]rune, len(s)) - i := 0 - for _, r := range s { - ret[i] = r - i++ - } - return ret[:i] + return []rune(s) } // MatchRunes return true if the runes matches the regex From 104f7f590c4d57982648e620b0309af76408a4f5 Mon Sep 17 00:00:00 2001 From: Dmitry Panov Date: Thu, 6 Aug 2020 17:37:08 +0100 Subject: [PATCH 2/2] Fixed starting at string's length. --- regexp.go | 3 +++ regexp_test.go | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/regexp.go b/regexp.go index fba1e33..7c7b01d 100644 --- a/regexp.go +++ b/regexp.go @@ -235,6 +235,9 @@ func (re *Regexp) getRunesAndStart(s string, startAt int) ([]rune, int) { ret[i] = r i++ } + if startAt == len(s) { + runeIdx = i + } return ret[:i], runeIdx } diff --git a/regexp_test.go b/regexp_test.go index f2a507d..f4246a5 100644 --- a/regexp_test.go +++ b/regexp_test.go @@ -877,6 +877,17 @@ func TestAlternationConstruct_Matches(t *testing.T) { } } +func TestStartAtEnd(t *testing.T) { + re := MustCompile("(?:)", 0) + m, err := re.FindStringMatchStartingAt("t", 1) + if err != nil { + t.Fatal(err) + } + if m == nil { + t.Fatal("Expected match") + } +} + func TestParserFuzzCrashes(t *testing.T) { var crashes = []string{ "(?'-", "(\\c0)", "(\\00(?())", "[\\p{0}", "(\x00?.*.()?(()?)?)*.x\xcb?&(\\s\x80)", "\\p{0}", "[0-[\\p{0}",