Skip to content

Commit

Permalink
Fixed unhandled exception #87
Browse files Browse the repository at this point in the history
  • Loading branch information
Knagis committed Jul 13, 2016
1 parent 7089a14 commit 63a6bb1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions CommonMark.Tests/SourcePositionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,21 @@ public void SourcePositionHtmlBlock1()
data.Substring(block.Block.SourcePosition, block.Block.SourceLength));
}

[TestMethod]
[TestCategory("SourcePosition - HTML Blocks")]
public void SourcePositionHtmlBlock1a()
{
var data = "<pre>\n</pre\n\n\nfoo";
var doc = Helpers.ParseDocument(data, Settings);

var block = doc.AsEnumerable()
.FirstOrDefault(o => o.Block != null && o.Block.Tag == Syntax.BlockTag.HtmlBlock);

Assert.IsNotNull(block);
Assert.AreEqual("<pre>\n</pre\n\n\nfoo",
data.Substring(block.Block.SourcePosition, block.Block.SourceLength));
}

[TestMethod]
[TestCategory("SourcePosition - HTML Blocks")]
public void SourcePositionHtmlBlock2()
Expand Down
4 changes: 2 additions & 2 deletions CommonMark/Parser/BlockMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ public static void Finalize(Block b, LineInfo line)
var includesThisLine = b.HtmlBlockType != HtmlBlockType.None && b.HtmlBlockType != HtmlBlockType.InterruptingBlock && b.HtmlBlockType != HtmlBlockType.NonInterruptingBlock;

// (b.SourcePosition >= line.LineOffset) determines if the block started on this line.
includesThisLine = includesThisLine || b.SourcePosition >= line.LineOffset && line.Line != null;
includesThisLine = includesThisLine || b.SourcePosition >= line.LineOffset;

if (includesThisLine)
if (includesThisLine && line.Line != null)
b.SourceLastPosition = line.CalculateOrigin(line.Line.Length, false);
else
b.SourceLastPosition = line.CalculateOrigin(0, false);
Expand Down

0 comments on commit 63a6bb1

Please sign in to comment.