Skip to content

Commit

Permalink
Merge pull request dlclark#28 from dop251/fix-start-at-end
Browse files Browse the repository at this point in the history
Fix start at end string-index-to-rune-index mapping problem.
  • Loading branch information
dlclark committed Aug 7, 2020
2 parents 4a0a6ac + 104f7f5 commit 74bac81
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
11 changes: 4 additions & 7 deletions regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,14 @@ func (re *Regexp) getRunesAndStart(s string, startAt int) ([]rune, int) {
ret[i] = r
i++
}
if startAt == len(s) {
runeIdx = i
}
return ret[:i], runeIdx
}

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
Expand Down
11 changes: 11 additions & 0 deletions regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down

0 comments on commit 74bac81

Please sign in to comment.