errata-ai / vale

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

Error when using capitalization style on heading with commas #235

Closed wilhelmer closed 3 years ago

wilhelmer commented 3 years ago

Vale version: 2.4.0

Using the following style ...

extends: capitalization
message: "'%s' should be in title case."
level: error
scope: heading
match: $title
style: Chicago
exceptions:
  - foo
  - bar
  - lorem
  - ipsum

... on this Markdown file ...

# foo, bar, and lorem Are Best Friends

Dummy text.

... results in the following error:

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

goroutine 80 [running]:
github.com/errata-ai/vale/check.title(0xc0011fe150, 0x22, 0xc000050840, 0x6, 0x6, 0xc000408700, 0xc00006a0f0, 0xc0011a3810)
    /home/travis/gopath/src/github.com/errata-ai/vale/check/variables.go:39 +0x31c
github.com/errata-ai/vale/check.(*Manager).addCapitalizationCheck.func1(0xc0011fe150, 0x22, 0xc000050840, 0x6, 0x6, 0xc000408700, 0xffffffffffffffff)
    /home/travis/gopath/src/github.com/errata-ai/vale/check/check.go:524 +0x6d
github.com/errata-ai/vale/check.checkCapitalization(0xc0011fe150, 0x22, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
    /home/travis/gopath/src/github.com/errata-ai/vale/check/check.go:393 +0x93
github.com/errata-ai/vale/check.(*Manager).addCapitalizationCheck.func4(0xc0011fe150, 0x22, 0xc0011ec000, 0x1208b60, 0x0, 0x0)
    /home/travis/gopath/src/github.com/errata-ai/vale/check/check.go:542 +0xc2
github.com/errata-ai/vale/lint.(*Linter).lintText.func1(0xc000026780, 0xc000c0cc80, 0xc0011fe150, 0x22, 0xc0003e68a0, 0x10, 0xc0011ec000, 0x0, 0xc0003e69c0, 0xe, ...)
    /home/travis/gopath/src/github.com/errata-ai/vale/lint/lint.go:303 +0x6c
created by github.com/errata-ai/vale/lint.(*Linter).lintText
    /home/travis/gopath/src/github.com/errata-ai/vale/lint/lint.go:302 +0x385

It's probably caused by the comma after "foo" and "bar". Without the comma, it works fine:

# foo and bar and lorem Are Best Friends

Dummy text.
jdkato commented 3 years ago

Thanks for the report.

This is a bug in an upstream library, but it will be fixed in the next release.