Skip to content

Commit

Permalink
Fixes issue xoofx#303
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster442 committed Mar 3, 2020
1 parent ef5b958 commit 2f0dd2a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
48 changes: 48 additions & 0 deletions src/Markdig.Tests/TestExceptionNotThrown.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using NUnit.Framework;

namespace Markdig.Tests
{
[TestFixture]
public class TestExceptionNotThrown
{
[Test]
public void DoesNotThrowIndexOutOfRangeException1()
{
Assert.DoesNotThrow(() =>
{
var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
Markdown.ToHtml("+-\n|\n+", pipeline);
});
}

[Test]
public void DoesNotThrowIndexOutOfRangeException2()
{
Assert.DoesNotThrow(() =>
{
var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
Markdown.ToHtml("+--\n|\n+0", pipeline);
});
}

[Test]
public void DoesNotThrowIndexOutOfRangeException3()
{
Assert.DoesNotThrow(() =>
{
var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
Markdown.ToHtml("+-\n|\n+\n0", pipeline);
});
}

[Test]
public void DoesNotThrowIndexOutOfRangeException4()
{
Assert.DoesNotThrow(() =>
{
var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
Markdown.ToHtml("+-\n|\n+0", pipeline);
});
}
}
}
5 changes: 5 additions & 0 deletions src/Markdig/Extensions/Tables/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public bool IsValid()
var rowSpan = cell.RowSpan - 1;
while (rowSpan > 0)
{
if (i+rowSpan > (rows.Length-1))
{
return false;
}

rows[i + rowSpan] += cell.ColumnSpan;
rowSpan--;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Markdig/Helpers/StringSlice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ public bool TrimStart()
// Strip leading spaces
for (; Start <= End; Start++)
{
if (!Text[Start].IsWhitespace())
if (Start < Text.Length
&& !Text[Start].IsWhitespace())
{
break;
}
Expand Down Expand Up @@ -349,7 +350,8 @@ public bool TrimEnd()
{
for (; Start <= End; End--)
{
if (!Text[End].IsWhitespace())
if (End < Text.Length
&& !Text[End].IsWhitespace())
{
break;
}
Expand Down

0 comments on commit 2f0dd2a

Please sign in to comment.