Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OptionOutputAsXml adds spaces to comments when using InnerHtml #412

Closed
spassarop opened this issue Oct 10, 2020 · 6 comments
Closed

OptionOutputAsXml adds spaces to comments when using InnerHtml #412

spassarop opened this issue Oct 10, 2020 · 6 comments
Assignees

Comments

@spassarop
Copy link

Description

I have some cases with HTML comments which I need to preserve their syntax. Some HTML examples can be modified (by changing the Comment property on a HtmlCommentNode). When I set OptionOutputAsXml to true, spaces are always added on different places.

In the fiddle I provide below I have a working example of the issue. This are my basic cases:

Original HTML HtmlDocument.DocumentNode.InnerHtml
<div>text <!-- comment --></div> <div>text <!-- comment  --></div>
<div>text <!--[if IE]> <!--[if gte 6]> comment <[endif]--><[endif]--></div> <div>text <!--[if IE]> <! - -[if gte 6]> comment <[endif] -->&lt;[endif]--&gt;</div>

For the first row case: A space has been added after "comment", now having two spaces.
For the second row case: Two spaces have been added on the second "<!--" and one after the first "[endif]".

Reading the code and changing options that don't conflict with my needs took me to no solution, also I don't understand why this could be normal behavior. That's why I'm creating this issue.

Fiddle

Custom Fiddle to reproduce the issue: https://dotnetfiddle.net/TkTqt0

Further technical details

  • HAP version: 1.11.24.
  • NET version: netcore 3.1, .NET Framework 4.7.2.

I hope there is a solution I'm not seeing or, if this is a real issue, it's easy to solve and could be included in the next release.
Thank you in advance.

@JonathanMagnan JonathanMagnan self-assigned this Oct 11, 2020
@JonathanMagnan
Copy link
Member

Hello @spassarop ,

He looked at this issue and here is the line that causes it: https://github.com/zzzprojects/html-agility-pack/blob/master/src/HtmlAgilityPack.Shared/HtmlNode.cs#L1830

It seems that comment, when OptionOutputAsXml is enabled, is rewrited.

The fix is easy but one problem I have is the Backward Compatiblity which people which currently use this library for a long time and which we will make a break for a small fix.

@spassarop
Copy link
Author

spassarop commented Oct 13, 2020

Well, that's a shame. I wouldn't like to use my own version of the library as the update process would be tedious compared with just updating a Nugget package.

I guess my only option is doing that if I want to keep using HAP, unless you have a workaround in mind. Close the issue if that's not the case.

Thanks for your time.

@JonathanMagnan
Copy link
Member

As said, I don't think changing the default behavior is a good thing since this library is so much used (We did it a few times in the past and every time a few days later, multiple people were reporting that their projects were no longer working).

However, I asked my developer to check a little bit more this week to check if we can add an option to better manage it.

@spassarop
Copy link
Author

I understand, I know backward compatibility is hard to maintain and usually there is a trade-off on fixing or keeping an issue.

Again, thank you very much for your time :)

@JonathanMagnan
Copy link
Member

Hello @spassarop ,

A new version has been released with the option OptionXmlForceOriginalComment. When enabled, it will exactly write the original comment instead of creating one.

Let me know if that's exactly what you were looking for.

Since that's a new option, this is still time to improve it without impacting anyone.

@spassarop
Copy link
Author

Hello @JonathanMagnan,

That option actually works and yes, it was exacly what I was looking for, keeping comments unchanged.

Thanks to the team!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants