Skip to content

Commit

Permalink
fix: unicode-related off-by-one
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Sep 7, 2020
1 parent 18ffd9a commit dbe2e18
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions rule/grammar.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,19 @@ func CheckWithLT(text, path string, f *core.File, debug bool) []core.Alert {
func matchToAlert(m match) core.Alert {
ctx := m.Context

target := ctx.Text[ctx.Offset : ctx.Offset+ctx.Length]
start, end := ctx.Offset, ctx.Offset+ctx.Length
// NOTE: this is necessary.
//
// See https://godoc.org/golang.org/x/exp/utf8string ??
target := string([]rune(ctx.Text)[start:end])

suggestions := replacementsToParams(m.Replacements)

alert := core.Alert{
Severity: "warning",
Match: target,
Check: "LanguageTool." + m.Rule.ID,
Span: []int{ctx.Offset, ctx.Offset + ctx.Length},
Span: []int{start, end},
Action: core.Action{
Name: "replace",
Params: suggestions,
Expand Down

0 comments on commit dbe2e18

Please sign in to comment.