Skip to content

Commit

Permalink
Fix a crash
Browse files Browse the repository at this point in the history
  • Loading branch information
walles committed Nov 6, 2019
1 parent fb3b6ab commit ea3dcf3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions m/matchRanges.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func _ToRunePositions(byteIndices [][]int, matchedString *string) [][2]int {

var returnMe [][2]int

if len(byteIndices) == 0 {
// Nothing to see here, move along
return returnMe
}

fromByte := byteIndices[len(returnMe)][0]
toByte := byteIndices[len(returnMe)][1]
fromRune := -1
Expand Down
12 changes: 12 additions & 0 deletions m/matchRanges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,15 @@ func TestUtf8(t *testing.T) {
assert.Assert(t, matchRanges.InRange(3)) // ä
assert.Assert(t, !matchRanges.InRange(4)) // -
}

func TestNoMatch(t *testing.T) {
// This test verifies that the match ranges are by rune rather than by byte
unicodes := "gris"
matchRanges := GetMatchRanges(&unicodes, regexp.MustCompile("apa"))

assert.Assert(t, !matchRanges.InRange(0))
assert.Assert(t, !matchRanges.InRange(1))
assert.Assert(t, !matchRanges.InRange(2))
assert.Assert(t, !matchRanges.InRange(3))
assert.Assert(t, !matchRanges.InRange(4))
}

0 comments on commit ea3dcf3

Please sign in to comment.