diff --git a/src/HtmlAgilityPack.Shared/HtmlAttribute.cs b/src/HtmlAgilityPack.Shared/HtmlAttribute.cs
index 0daa3bed..d71d3ae2 100644
--- a/src/HtmlAgilityPack.Shared/HtmlAttribute.cs
+++ b/src/HtmlAgilityPack.Shared/HtmlAttribute.cs
@@ -170,7 +170,10 @@ public string Value
if (_value == null)
{
- _value = _ownerdocument.Text.Substring(_valuestartindex, _valuelength);
+ if (_ownerdocument.Text != null && _valuestartindex + _valuelength <= _ownerdocument.Text.Length)
+ _value = _ownerdocument.Text.Substring(_valuestartindex, _valuelength);
+ else
+ _value = "";
if (!_ownerdocument.BackwardCompatibility)
{
diff --git a/src/HtmlAgilityPack.Shared/HtmlNode.cs b/src/HtmlAgilityPack.Shared/HtmlNode.cs
index bdbd77da..cbb4ccb8 100644
--- a/src/HtmlAgilityPack.Shared/HtmlNode.cs
+++ b/src/HtmlAgilityPack.Shared/HtmlNode.cs
@@ -565,7 +565,9 @@ public virtual string OuterHtml
return string.Empty;
}
- return _ownerdocument.Text.Substring(_outerstartindex, _outerlength);
+ if (_ownerdocument.Text != null && _outerstartindex + _outerlength <= _ownerdocument.Text.Length)
+ return _ownerdocument.Text.Substring(_outerstartindex, _outerlength);
+ return string.Empty;
}
}