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

OuterLength is incorrect, refering to the reconstructed OuterHtml and not the original

Open sperlis opened this issue 3 months ago • 6 comments

In this sample HTML:

   <html>
      <body>
        <div class='aaa' /><div class='bbb'>
        </div>
     </body>
   </html>

When I examine the node of div with class 'aaa' the OuterHtml is <div class='aaa'></div> as it's reconstructed. The OuterLength is therefore the outer length of the OuterHtml propery (23), and not the original outer length (19). The original is stored in the _outerlength private property. I need access to the original outer length or be able to get the original OuterHtml to get the length from there.

sperlis avatar Sep 21 '25 07:09 sperlis

Hello @sperlis,

I tested and can confirm everything you mentioned.

This week, I’ll look into adding a new property, something like OriginalOuterLength, that will return the _outerlength.

Best Regards,

Jon

JonathanMagnan avatar Sep 22 '25 12:09 JonathanMagnan

Thank you, this is much appreciated!

Shahar

sperlis avatar Sep 28 '25 13:09 sperlis

If you're already looking at this, I have another interesting (I think) case. If you have bad HTML

<p>Text:
  <div>more text</div>
</p>

Since this is illegal, the first <p> is auto-closed with synthetic "bad" HtmlNode. Which is fine. What goes wrong is the outer length. OuterLength is 10 (correct), but _outerlength and _innerlength are wrong negative numbers (I've seen -1 and -4, not sure what's the significance).

If you're already poking around in there, it might be another thing to look at :)

Thanks again!

sperlis avatar Sep 28 '25 16:09 sperlis

Hello @sperlis ,

We added a new property OriginalOuterLength that should be released soon.

As for the second issue, unfortunately we didn't succeed to fix it. We indeed know exactly where it the code that happens but fixing it currently involved some major change and to be honest, we don't have enough unit test to know exactly which side impact will happens.

Best Regards,

Jon

JonathanMagnan avatar Oct 01 '25 16:10 JonathanMagnan

Hello @sperlis ,

The new property has been added in the latest version: https://github.com/zzzprojects/html-agility-pack/releases/tag/v1.12.4

Thank you again for your suggestion.

Best Regards,

Jon

JonathanMagnan avatar Oct 03 '25 14:10 JonathanMagnan

Thank you! appreciate your response.

If you do get around to examine the second issue it would be nice to have, but I understand it can be sensitive.

Thanks again, Shahar

sperlis avatar Oct 09 '25 14:10 sperlis