Skip to content

Comments

fix: skip empty citation segments after semicolon split#349

Merged
kjk merged 1 commit intogomarkdown:masterfrom
vnykmshr:fix-citation-panic
Feb 17, 2026
Merged

fix: skip empty citation segments after semicolon split#349
kjk merged 1 commit intogomarkdown:masterfrom
vnykmshr:fix-citation-panic

Conversation

@vnykmshr
Copy link
Contributor

Fixes #348.

citation() panics when bytes.Split produces empty segments from adjacent or trailing semicolons in citation syntax (e.g. [@;], [@ref;], [@ref1;;@ref2]).

What changed

  • parser/citation.go: added len(citation) == 0 check with continue after TrimSpace, before indexing into the slice
  • parser/citation_test.go: added TestCitationEmptySegment covering the three panic cases

Using continue preserves valid citations on either side of an empty segment.

citation() panics with index-out-of-range when input contains empty
segments after splitting on semicolons (e.g. [@;], [@ref;], [@ref1;;@ref2]).

bytes.Split produces empty slices for adjacent/trailing semicolons.
Add a length check before indexing into the trimmed citation slice.
@kjk kjk merged commit 554ac1d into gomarkdown:master Feb 17, 2026
1 check passed
@kjk
Copy link
Contributor

kjk commented Feb 17, 2026

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

citation() panics on empty segment after semicolon split

2 participants