diff --git a/src/HtmlAgilityPack.Shared/HtmlNode.cs b/src/HtmlAgilityPack.Shared/HtmlNode.cs index 92c41c9..5f81847 100644 --- a/src/HtmlAgilityPack.Shared/HtmlNode.cs +++ b/src/HtmlAgilityPack.Shared/HtmlNode.cs @@ -2006,20 +2006,23 @@ internal void UpdateLastNode() HtmlNode newLast = null; if (_prevwithsamename == null || !_prevwithsamename._starttag) { - foreach (var openNode in _ownerdocument.Openednodes) - { - if ((openNode.Key < _outerstartindex || openNode.Key > (_outerstartindex + _outerlength)) && openNode.Value._name == _name) - { - if (newLast == null && openNode.Value._starttag) - { - newLast = openNode.Value; - } - else if (newLast !=null && newLast.InnerStartIndex < openNode.Key && openNode.Value._starttag) - { - newLast = openNode.Value; - } - } - } + if (_ownerdocument.Openednodes != null) + { + foreach (var openNode in _ownerdocument.Openednodes) + { + if ((openNode.Key < _outerstartindex || openNode.Key > (_outerstartindex + _outerlength)) && openNode.Value._name == _name) + { + if (newLast == null && openNode.Value._starttag) + { + newLast = openNode.Value; + } + else if (newLast != null && newLast.InnerStartIndex < openNode.Key && openNode.Value._starttag) + { + newLast = openNode.Value; + } + } + } + } } else { diff --git a/src/Tests/HtmlAgilityPack.Tests.Net45/HtmlDocumentTests.cs b/src/Tests/HtmlAgilityPack.Tests.Net45/HtmlDocumentTests.cs index 8a61559..81c4ac6 100644 --- a/src/Tests/HtmlAgilityPack.Tests.Net45/HtmlDocumentTests.cs +++ b/src/Tests/HtmlAgilityPack.Tests.Net45/HtmlDocumentTests.cs @@ -945,6 +945,27 @@ public void GetClasses_WhereClassWithWhitespacePassed_ShouldNotBeEmpty() Assert.IsNotEmpty(aTag.GetClasses()); } + [Test] + public void LoadHtml_WhenHtmlHasUnclosedTags_AndOptionCheckSyntaxFalse_ShouldNotThrowException() + { + var html = "
html