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.63k stars 375 forks source link

When we have a closing tag before the current open tag is closed we have different results between HAP and Chrome rendering #542

Open pauloortins opened 6 months ago

pauloortins commented 6 months ago

When we have a closing tag before the current open tag is closed we have different results between HAP and Chrome rendering. While chrome moves the wrong closing tag to after the current tag is closed, HAP closes the current tag ending up with an extra closing tag.

HTML: <html><head></head><body><div><form></div></form></body></html>
HAP Result: <html><head></head><body><div><form></form></div></form></body></html>
Chrome Result: <html><head></head><body><div><form></form></div></body></html>

This is the test I used:

var html = @"<html><head></head><body><div><form></div></form></body></html>";
var doc = new HtmlDocument();
doc.LoadHtml(html);
var newHtml = doc.DocumentNode.OuterHtml;  //<html><head></head><body><div><form></form></div></form></body></html>
var res = @"<html><head></head><body><div><form></form></div></body></html>"; //chrome or edge rendering results
var b = newHtml == res; //false