From 118d28f886f0af1b1c7d7430d2f7ee8d5e4eca1c Mon Sep 17 00:00:00 2001 From: Sergey Nozhenko Date: Fri, 3 Jan 2025 04:29:24 +0300 Subject: [PATCH 1/2] Prevent GridTableParser from looking beyond the end of a line. --- src/Markdig/Extensions/Tables/GridTableParser.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Markdig/Extensions/Tables/GridTableParser.cs b/src/Markdig/Extensions/Tables/GridTableParser.cs index 0dc268fa..6e6d562a 100644 --- a/src/Markdig/Extensions/Tables/GridTableParser.cs +++ b/src/Markdig/Extensions/Tables/GridTableParser.cs @@ -135,6 +135,7 @@ private BlockState HandleNewRow(BlockProcessor processor, GridTableState tableSt private static void SetRowSpanState(List 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) @@ -142,7 +143,7 @@ private static void SetRowSpanState(List columns, St 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)) { From 7b6d659bbd803e401a1d5ca705cb1f69267a981b Mon Sep 17 00:00:00 2001 From: Sergey Nozhenko Date: Fri, 3 Jan 2025 07:03:28 +0300 Subject: [PATCH 2/2] A test has been added. --- src/Markdig.Tests/MiscTests.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Markdig.Tests/MiscTests.cs b/src/Markdig.Tests/MiscTests.cs index 85847988..77b95059 100644 --- a/src/Markdig.Tests/MiscTests.cs +++ b/src/Markdig.Tests/MiscTests.cs @@ -317,4 +317,24 @@ public void RootInlineInTableCellHasCorrectSourceSpan() Assert.That(paragraph.Inline.Span.Start == paragraph.Inline.FirstChild.Span.Start); Assert.That(paragraph.Inline.Span.End == paragraph.Inline.LastChild.Span.End); } + + [Test] + public void TestGridTableShortLine() + { + var input = @" ++--+ +| | ++-"; + + var expected = @" ++ + + + + +
+"; + TestParser.TestSpec(input, expected, new MarkdownPipelineBuilder().UseGridTables().Build()); + } }