Fix IndexOutOfRangeException when parsing markdown tables without trailing pipes#7133
Merged
adamsitnik merged 3 commits intomainfrom Dec 11, 2025
Merged
Fix IndexOutOfRangeException when parsing markdown tables without trailing pipes#7133adamsitnik merged 3 commits intomainfrom
adamsitnik merged 3 commits intomainfrom
Conversation
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix parsing of markdown tables without trailing pipe
Fix IndexOutOfRangeException when parsing markdown tables without trailing pipes
Dec 11, 2025
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an IndexOutOfRangeException that occurred when parsing markdown tables without trailing pipe (|) characters. The Markdig library parses these tables differently, causing table.ColumnDefinitions.Count to return inconsistent values: for tables with trailing pipes it returns actualColumns + 1, but for tables without trailing pipes it returns the actual column count. The previous code assumed all tables needed a -1 adjustment, which failed for tables without trailing pipes.
Key Changes
- Replaced hardcoded
table.ColumnDefinitions.Count - 1with a dynamicGetColumnCount()helper function that calculates columns by examining actual row cells and summing theirColumnSpanvalues - Added comprehensive test case
SupportsTablesWithoutTrailingPipes()demonstrating the fix works for tables with empty cells and multi-row scenarios
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Libraries/Microsoft.Extensions.DataIngestion.Markdig/MarkdownParser.cs | Introduces GetColumnCount() local function to dynamically calculate column count by iterating through table rows and summing cell column spans, replacing unreliable ColumnDefinitions.Count - 1 hardcode |
| test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkdownReaderTests.cs | Adds test case with real-world table from runtime docs featuring tables without trailing pipes, empty cells, and 10 rows to validate the fix |
src/Libraries/Microsoft.Extensions.DataIngestion.Markdig/MarkdownParser.cs
Show resolved
Hide resolved
SamMonoRT
approved these changes
Dec 11, 2025
ericstj
pushed a commit
to ericstj/extensions
that referenced
this pull request
Dec 11, 2025
…iling pipes (dotnet#7133) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Markdig parses tables without trailing
|characters differently than tables with them, causingtable.ColumnDefinitions.Countto vary. The code assumed all tables needed-1adjustment for column count, which failed for tables without trailing pipes.Example of failing markdown:
Changes
table.ColumnDefinitions.Count - 1with dynamicGetColumnCount()that examines actual row cells and their column spansThe fix calculates column count by iterating rows and summing
ColumnSpanvalues, returning the maximum found. This handles both table formats correctly.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
securitytools.pkgs.visualstudio.com/opt/hostedtoolcache/CodeQL/2.23.6/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.23.6/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
|#7132💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Microsoft Reviewers: Open in CodeFlow