zzzprojects / html-agility-pack

Html Agility Pack (HAP) is a free and open-source HTML parser written in C# to read/write DOM and supports plain XPATH or XSLT. It is a .NET code library that allows you to parse "out of the web" HTML files.
https://html-agility-pack.net
MIT License
2.65k stars 375 forks source link

Setting node name seems to work only partially #497

Closed arekdygas closed 1 year ago

arekdygas commented 1 year ago

1. Description

When I execute the following code:

var node = HtmlNode.CreateNode("<div data-num=\"10\">aaa</div>");
//node.Attributes.Remove("data-num");
node.Name = "p";
Console.WriteLine(node.Name);
Console.WriteLine(node.OuterHtml);

node.Name is correctly displayed as p, but there's still div in OuterHtml. But after uncommenting the line with attribute removal, this works correctly.

I suspect this has something to do with setting _changed flag, which is not called on Name setter.

2. Exception

--

3. Fiddle or Project

https://dotnetfiddle.net/6s8zO7

4. Any further technical details

JonathanMagnan commented 1 year ago

Hello @arekdygas ,

Thank you for reporting.

We will look at it.

Best Regards,

Jon


Sponsorship Help us improve this library

Performance Libraries context.BulkInsert(list, options => options.BatchSize = 1000); Entity Framework ExtensionsDapper Plus

Runtime Evaluation Eval.Execute("x + y", new {x = 1, y = 2}); // return 3 C# Eval Function

JonathanMagnan commented 1 year ago

Hello @arekdygas ,

Sorry for the long delay.

This issue has been fixed in the v1.11.47

Let me know if everything now works as expected.

Best Regards,

Jon

arekdygas commented 1 year ago

Hello @JonathanMagnan ,

Looking at the code changes, it's probably fixed, but my test failed again, because you uploaded version 46 as 47 to nuget ;)

Best regards, Arek

JonathanMagnan commented 1 year ago

Hello @arekdygas ,

100% my mistake! The v1.11.48 has been released with the right assembly version and with the fix this time ;)

Best Regards,

Jon

arekdygas commented 1 year ago

Fixed now - thanks! :)

Best regards, Arek