From fb35448a4e5138b28125ae02766c20965af3e7e7 Mon Sep 17 00:00:00 2001 From: John Freeman Date: Wed, 31 May 2023 13:14:14 +1000 Subject: [PATCH] When traversing the DOM during SetChanged track the depth to avoid StackOverflowException --- src/HtmlAgilityPack.Shared/HtmlNode.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/HtmlAgilityPack.Shared/HtmlNode.cs b/src/HtmlAgilityPack.Shared/HtmlNode.cs index 629833c6..69c5ec29 100644 --- a/src/HtmlAgilityPack.Shared/HtmlNode.cs +++ b/src/HtmlAgilityPack.Shared/HtmlNode.cs @@ -2163,12 +2163,17 @@ public void SetParent(HtmlNode parent) #region Internal Methods - internal void SetChanged() + internal void SetChanged(int level = 0) { + if (level > HtmlDocument.MaxDepthLevel) + { + throw new ArgumentException(HtmlNode.DepthLevelExceptionMessage); + } + _changed = true; if (ParentNode != null) { - ParentNode.SetChanged(); + ParentNode.SetChanged(level + 1); } }