MarkdownReader throws ArgumentNullException on a table with an empty cell

Open Beginner friendly
#7,956 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp
Domain
backend

Research direction

Start in MarkdownParser.GetCells and follow its single-block case into MapBlock; the stack trace identifies the path that sends an empty paragraph to the element constructor. Check existing parser tests for table cells and add coverage showing an empty cell maps to null while nonempty cells still parse. Done when the reported table reads without throwing and the empty cell is represented as null.

Written by the indexing model from the issue text.

Description

area-ai untriaged

MarkdownReader throws when a Markdown table has an empty cell, so one empty cell fails the whole document.

Package: Microsoft.Extensions.DataIngestion.Markdig 11.0.0-preview.1.26560.3

var reader = new MarkdownReader();
using var stream = new MemoryStream(Encoding.UTF8.GetBytes("| a | b |\n| --- | --- |\n|  | 1 |\n"));
await reader.ReadAsync(stream, "doc", "text/markdown"); // throws

The same table with x in the empty cell reads fine.

System.ArgumentNullException: Value cannot be null. (Parameter 'markdown')
   at Microsoft.Extensions.DataIngestion.IngestionDocumentElement..ctor(String markdown)
   at Microsoft.Extensions.DataIngestion.IngestionDocumentParagraph..ctor(String markdown)
   at Microsoft.Extensions.DataIngestion.MarkdownParser.MapLeafBlockToElement(LeafBlock block, Boolean previousWasBreak, String elementMarkdown)
   at Microsoft.Extensions.DataIngestion.MarkdownParser.MapBlock(String documentMarkdown, Boolean previousWasBreak, Block block)
   at Microsoft.Extensions.DataIngestion.MarkdownParser.GetCells(Table table, String outputContent)
   at Microsoft.Extensions.DataIngestion.MarkdownParser.MapBlock(String documentMarkdown, Boolean previousWasBreak, Block block)
   at Microsoft.Extensions.DataIngestion.MarkdownParser.Map(MarkdownDocument markdownDocument, String documentMarkdown, String identifier)
   at Microsoft.Extensions.DataIngestion.MarkdownParser.Parse(String markdown, String identifier)
   at Microsoft.Extensions.DataIngestion.MarkdownReader.ReadAsync(Stream source, String identifier, String mediaType, CancellationToken cancellationToken)

Markdig gives an empty cell one empty ParagraphBlock, so GetCells takes the 1 => branch rather than 0 => null. MapBlock then passes an empty string to IngestionDocumentParagraph, and IngestionDocumentElement's constructor rejects null or empty. The code is the same on main.

Empty cells are common in tables that come from PDFs, OCR and spreadsheets: in our corpus 5 of 16 documents failed to ingest this way. I'd expect an empty cell to map to null, like a cell with no blocks.

We work around it by writing U+200B into empty cells before reading and removing it from the chunks afterwards.

Dominant language
C#
Stars
3.3k
Forks
919
Avg merge
2d 2h
Merged PRs (30d)
35

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/extensions

All issues in dotnet/extensions

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.