Skip to content

Commit 5528023

Browse files
authored
Merge pull request #844 from snnz/fix-gridtables
Prevent GridTableParser from looking beyond the end of a line.
2 parents d53fd0e + f93b9d7 commit 5528023

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Markdig.Tests/MiscTests.cs

+20
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,26 @@ public void RootInlineInTableCellHasCorrectSourceSpan()
318318
Assert.That(paragraph.Inline.Span.End == paragraph.Inline.LastChild.Span.End);
319319
}
320320

321+
[Test]
322+
public void TestGridTableShortLine()
323+
{
324+
var input = @"
325+
+--+
326+
| |
327+
+-";
328+
329+
var expected = @"<table>
330+
<col style=""width:100%"" />
331+
<tbody>
332+
<tr>
333+
<td></td>
334+
</tr>
335+
</tbody>
336+
</table>
337+
";
338+
TestParser.TestSpec(input, expected, new MarkdownPipelineBuilder().UseGridTables().Build());
339+
}
340+
321341
[Test]
322342
public void TestDefinitionListInListItemWithBlankLine()
323343
{

src/Markdig/Extensions/Tables/GridTableParser.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,15 @@ private BlockState HandleNewRow(BlockProcessor processor, GridTableState tableSt
135135
private static void SetRowSpanState(List<GridTableState.ColumnSlice> columns, StringSlice line, out bool isHeaderRow, out bool hasRowSpan)
136136
{
137137
var lineStart = line.Start;
138+
var lineEnd = line.End;
138139
isHeaderRow = line.PeekChar() == '=' || line.PeekChar(2) == '=';
139140
hasRowSpan = false;
140141
foreach (var columnSlice in columns)
141142
{
142143
if (columnSlice.CurrentCell != null)
143144
{
144145
line.Start = lineStart + columnSlice.Start + 1;
145-
line.End = lineStart + columnSlice.End - 1;
146+
line.End = Math.Min(lineStart + columnSlice.End - 1, lineEnd);
146147
line.Trim();
147148
if (line.IsEmptyOrWhitespace() || !IsRowSeparator(line))
148149
{

0 commit comments

Comments
 (0)