-
Notifications
You must be signed in to change notification settings - Fork 850
Fix IndexOutOfRangeException when parsing markdown tables without trailing pipes #7133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: adamsitnik <[email protected]>
Co-authored-by: adamsitnik <[email protected]>
adamsitnik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks great! thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
…iling pipes (dotnet#7133) Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: adamsitnik <[email protected]>
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