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

(2) The html rendering result is different from the html output result #532

Closed colindcli closed 7 months ago

colindcli commented 8 months ago

Similar to the previous situation in #529

spandiv

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

Test URL: https://dotnetfiddle.net/HrDL5G

colindcli commented 8 months ago

second example:

There is also a more special code. The code has been simplified to the minimum. The outermost div is abnormal.

other

            var html = @"
<div>
    <span>
        <font>
            <div>
                <span>
                    <div></div>
                </span>
            </div>
        </font>
    </span>
    <span></span>
</div>";
            var doc = new HtmlDocument();
            doc.LoadHtml(html);
            var newHtml = doc.DocumentNode.OuterHtml;

newHtml value is:

<div>
    <span>
        <font>
            <div>
                <span></span>
                <div></div>
            </div>
        </font>
    </span>
</div>
<span></span>

div position is wrong!

Test URL: https://dotnetfiddle.net/K1JXDE

Jagailo commented 8 months ago

I also want to join this issue, until version 57 this didn't cause an exception:

HtmlNode.CreateNode("<span><div></div></span>");

This code doesn't contain <p>, Chromium also allows such HTML image

JonathanMagnan commented 8 months ago

Hello,

Thank you for reporting. We are already aware of this issue here: https://github.com/zzzprojects/html-agility-pack/issues/531

It should be fixed really soon.

Best Regards,

Jon

JonathanMagnan commented 8 months ago

Hello @colindcli , @Jagailo

The code added in v1.11.57 has been reverted in v1.11.58, so this issue should no longer happen.

More information can be found in the issue #529 for you @colindcli

Best Regards,

Jon