Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions parser/citation.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func citation(p *Parser, data []byte, offset int) (int, ast.Node) {
for _, citation := range citations {
var suffix []byte
citation = bytes.TrimSpace(citation)
if len(citation) == 0 {
continue
}
j := 0
if citation[j] != '@' {
// not a citation, drop out entirely.
Expand Down
17 changes: 17 additions & 0 deletions parser/citation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ func TestCitationSuffix(t *testing.T) {
}
}

func TestCitationEmptySegment(t *testing.T) {
p := New()
p.extensions |= Mmark

// These inputs should not panic
inputs := [][]byte{
[]byte(`[@;]`),
[]byte(`[@ref;]`),
[]byte(`[@ref1;;@ref2]`),
}
for _, data := range inputs {
_, node := citation(p, data, 0)
// empty segments are skipped; result depends on remaining valid citations
_ = node
}
}

func TestCitationSuffixMultiple(t *testing.T) {
data := []byte(`[@?RFC1034; @!RFC1035, p. 144, more]`)

Expand Down