blackfriday icon indicating copy to clipboard operation
blackfriday copied to clipboard

Definition list immediately followed by references causes panic

Open SamWhited opened this issue 4 years ago • 0 comments

Running the following minimal working example:

package main

import (
	"gopkg.in/russross/blackfriday.v2"
)

func main() {
	blackfriday.Run([]byte(`
whatever
: foo

[panics]: [test]
[test]: done`))
}

results in a panic:

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

goroutine 1 [running]:
gopkg.in/russross/blackfriday%2ev2.(*Markdown).listItem(0xc000108900, 0xc0000b603a, 0x24, 0x24, 0xc0000ffce8, 0x9)
        /home/sam/go/pkg/mod/gopkg.in/russross/[email protected]/block.go:1327 +0xb0a
gopkg.in/russross/blackfriday%2ev2.(*Markdown).list(0xc000108900, 0xc0000b6031, 0x2d, 0x2d, 0x2, 0x0)
        /home/sam/go/pkg/mod/gopkg.in/russross/[email protected]/block.go:1134 +0x101
gopkg.in/russross/blackfriday%2ev2.(*Markdown).paragraph(0xc000108900, 0xc0000b6031, 0x2d, 0x2d, 0x0)
        /home/sam/go/pkg/mod/gopkg.in/russross/[email protected]/block.go:1506 +0x4e5
gopkg.in/russross/blackfriday%2ev2.(*Markdown).block(0xc000108900, 0xc0000b6030, 0x2e, 0x2e)
        /home/sam/go/pkg/mod/gopkg.in/russross/[email protected]/block.go:194 +0x358
gopkg.in/russross/blackfriday%2ev2.(*Markdown).Parse(0xc000108900, 0xc0000b6030, 0x2e, 0x2e, 0x0)
        /home/sam/go/pkg/mod/gopkg.in/russross/[email protected]/markdown.go:404 +0x4d
gopkg.in/russross/blackfriday%2ev2.Run(0xc0000b6030, 0x2e, 0x2e, 0x0, 0x0, 0x0, 0x0, 0x4df700, 0xc000088058)
        /home/sam/go/pkg/mod/gopkg.in/russross/[email protected]/markdown.go:388 +0x1b9
main.main()
        /home/sam/testmarkdown/main.go:8 +0x7e
exit status 2

Adding some sort of separator between the definition list and the references fixes things:

package main

import (
	"gopkg.in/russross/blackfriday.v2"
)

func main() {
	blackfriday.Run([]byte(`
whatever
: foo

fixed

[panics]: [test]
[test]: done`))
}

This looks vaguely similar to #420, #418, #417, #416, and #415, but I couldn't be sure and they didn't appear to have any comments so I wanted to add a bit more spam to the queue :)

SamWhited avatar Jan 03 '20 22:01 SamWhited