Skip to content

Commit

Permalink
Merge pull request #844 from snnz/fix-gridtables
Browse files Browse the repository at this point in the history
Prevent GridTableParser from looking beyond the end of a line.
  • Loading branch information
xoofx authored Jan 9, 2025
2 parents d53fd0e + f93b9d7 commit 5528023
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/Markdig.Tests/MiscTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,26 @@ public void RootInlineInTableCellHasCorrectSourceSpan()
Assert.That(paragraph.Inline.Span.End == paragraph.Inline.LastChild.Span.End);
}

[Test]
public void TestGridTableShortLine()
{
var input = @"
+--+
| |
+-";

var expected = @"<table>
<col style=""width:100%"" />
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
";
TestParser.TestSpec(input, expected, new MarkdownPipelineBuilder().UseGridTables().Build());
}

[Test]
public void TestDefinitionListInListItemWithBlankLine()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Markdig/Extensions/Tables/GridTableParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,15 @@ private BlockState HandleNewRow(BlockProcessor processor, GridTableState tableSt
private static void SetRowSpanState(List<GridTableState.ColumnSlice> columns, StringSlice line, out bool isHeaderRow, out bool hasRowSpan)
{
var lineStart = line.Start;
var lineEnd = line.End;
isHeaderRow = line.PeekChar() == '=' || line.PeekChar(2) == '=';
hasRowSpan = false;
foreach (var columnSlice in columns)
{
if (columnSlice.CurrentCell != null)
{
line.Start = lineStart + columnSlice.Start + 1;
line.End = lineStart + columnSlice.End - 1;
line.End = Math.Min(lineStart + columnSlice.End - 1, lineEnd);
line.Trim();
if (line.IsEmptyOrWhitespace() || !IsRowSeparator(line))
{
Expand Down

0 comments on commit 5528023

Please sign in to comment.