Skip to content
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

Fixes issue #303 #404

Merged
merged 1 commit into from
Mar 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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