errata-ai / vale

:pencil: A markup-aware linter for prose built with speed and extensibility in mind.
https://vale.sh
MIT License
4.52k stars 155 forks source link

occurrence: `panic: runtime error: index out of range [0] with length 0` when min > 0 #367

Closed dboshardy closed 3 years ago

dboshardy commented 3 years ago

When specifying an occurrence style with a min > 0 and a token and the token not in the text being processed, the following panic happens:

panic: runtime error: index out of range [0] with length 0

goroutine 13 [running]:
github.com/errata-ai/vale/v2/internal/check.Occurrence.Run({{{{0x0, 0x0}, {0x0, 0x0, 0x0}}, {0x0, 0x0}, {0xc000988720, 0xa}, {0xc000988828, ...}, ...}, ...}, ...)
        github.com/errata-ai/vale/v2/internal/check/occurrence.go:66 +0x24b
github.com/errata-ai/vale/v2/internal/lint.(*Linter).lintBlock(0xc000a81918, 0xc00063e160, {{0xc0019fa900, 0x451}, 0xffffffffffffffff, {0xc001659860, 0x7}, {0xc0019fa900, 0x451}}, 0x21, ...)
        github.com/errata-ai/vale/v2/internal/lint/lint.go:225 +0x229
github.com/errata-ai/vale/v2/internal/lint.Linter.lintSizedScopes({0xc000620cc0, 0x0, 0x0, 0xc0004f9188, 0x1ea97a0, {0x0, 0x0, 0x0}, {0x0, 0x0, ...}, ...}, ...)
        github.com/errata-ai/vale/v2/internal/lint/ast.go:164 +0x411
github.com/errata-ai/vale/v2/internal/lint.Linter.lintHTMLTokens({0xc000620cc0, 0x0, 0x0, 0xc0004f9188, 0x1ea97a0, {0x0, 0x0, 0x0}, {0x0, 0x0, ...}, ...}, ...)
        github.com/errata-ai/vale/v2/internal/lint/ast.go:118 +0xb45
github.com/errata-ai/vale/v2/internal/lint.Linter.lintMarkdown({0xc000620cc0, 0x0, 0x0, 0xc0004f9188, 0x1ea97a0, {0x0, 0x0, 0x0}, {0x0, 0x0, ...}, ...}, ...)
        github.com/errata-ai/vale/v2/internal/lint/md.go:59 +0x194
github.com/errata-ai/vale/v2/internal/lint.(*Linter).lintFile(0xc001097c80, {0x7ffeefbff525, 0xc0001081e0})
        github.com/errata-ai/vale/v2/internal/lint/lint.go:174 +0x2f8
github.com/errata-ai/vale/v2/internal/lint.(*Linter).lintFiles.func1.1.1({0x7ffeefbff525, 0x1})
        github.com/errata-ai/vale/v2/internal/lint/lint.go:119 +0x5b
created by github.com/errata-ai/vale/v2/internal/lint.(*Linter).lintFiles.func1.1
        github.com/errata-ai/vale/v2/internal/lint/lint.go:117 +0x21d

Looking at the source, it looks like loc is empty since no match is found.

dboshardy commented 3 years ago

What snappy service! As I forked to fix this, I saw the fix was made to v2. Thanks!