ArgumentNullException when parsing empty string with trackTrivia=true #565

Closed
opened 2026-01-29 14:39:50 +00:00 by claunia · 0 comments
Owner

Originally created by @meziantou on GitHub (Sep 27, 2022).

Repro code:

Markdown.Parse("", trackTrivia: true);
System.ArgumentNullException
  Message=Value cannot be null.
  Source=System.Private.CoreLib
  StackTrace:
   at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
   at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
   at Markdig.Parsers.MarkdownParser.Parse(String text, MarkdownPipeline pipeline, MarkdownParserContext context)
   at Markdig.Markdown.Parse(String markdown, MarkdownPipeline pipeline, MarkdownParserContext context)
   at Markdig.Markdown.Parse(String markdown, Boolean trackTrivia)
   at Program.<Main>$(String[] args)

It only occurs for empty strings when using trackTrivia: true.

Originally created by @meziantou on GitHub (Sep 27, 2022). Repro code: ````c# Markdown.Parse("", trackTrivia: true); ```` ```` System.ArgumentNullException Message=Value cannot be null. Source=System.Private.CoreLib StackTrace: at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument) at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection) at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection) at Markdig.Parsers.MarkdownParser.Parse(String text, MarkdownPipeline pipeline, MarkdownParserContext context) at Markdig.Markdown.Parse(String markdown, MarkdownPipeline pipeline, MarkdownParserContext context) at Markdig.Markdown.Parse(String markdown, Boolean trackTrivia) at Program.<Main>$(String[] args) ```` It only occurs for empty strings when using `trackTrivia: true`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#565