html-agility-pack icon indicating copy to clipboard operation
html-agility-pack copied to clipboard

Modify a `#text` node name causes a `StackOverflowException`

Open BrianPainter88 opened this issue 1 year ago • 2 comments

Here is what to include in your request to make sure we implement a solution as quickly as possible.

1. Description

My application is using a process in which it loops through certain nodes and removes any namespaces that may be appended to the name. After the upgrade to version 1.11.48, a StackOverflowException is encountered when updating the HtmlNode.Name property and attempting to access either the HtmlNode.InnerHtml or HtmlNode.InnerText properties.

2. Exception

Exception of type 'System.StackOverflowException' was thrown.

3. Fiddle or Project

https://dotnetfiddle.net/Q1LM01

using System;
using HtmlAgilityPack;

public class Program
{
	public static void Main()
	{
		var document = new HtmlDocument();
		document.LoadHtml("a");

		foreach (var node in document.DocumentNode.ChildNodes)
		{
			if (node.Name == "#text")
			{
				node.Name = node.Name;
			}
		}
		
		foreach (var node in document.DocumentNode.ChildNodes)
		{
			Console.WriteLine(node.InnerHtml);
		}
	}
}

4. Any further technical details

Add any relevant detail can help us, such as:

  • HAP version: started in 1.11.48
  • NET version: any

BrianPainter88 avatar Apr 25 '24 17:04 BrianPainter88

Hello @BrianPainter88 ,

Thank you for reporting, the issue has been fixed for HtmlTextNode.

A new version should be released early this week.

Best Regards,

Jon

JonathanMagnan avatar Apr 27 '24 23:04 JonathanMagnan

Hello @BrianPainter88 ,

A new version has been released today.

Could you let me know if everything is now working with the latest version?

Best Regards,

Jon

JonathanMagnan avatar Apr 30 '24 16:04 JonathanMagnan