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

NullReferenceException when HTML payload ends with a comment #459

Closed
enkelmedia opened this issue Nov 22, 2016 · 7 comments
Closed

NullReferenceException when HTML payload ends with a comment #459

enkelmedia opened this issue Nov 22, 2016 · 7 comments

Comments

@enkelmedia
Copy link

enkelmedia commented Nov 22, 2016

When I'm parsing this code I get an error.

<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body></body>
</html>
<!-- Comment -->
System.NullReferenceException: Object reference not set to an instance of an object.\r\n   

at AngleSharp.AutoSelectedMarkupFormatter.Comment(IComment comment)\r\n   at AngleSharp.Dom.Comment.ToHtml(TextWriter writer, IMarkupFormatter formatter)\r\n   at AngleSharp.Dom.Collections.NodeList.ToHtml(TextWriter writer, IMarkupFormatter formatter)\r\n   

at AngleSharp.Extensions.FormatExtensions.ToHtml(IMarkupFormattable markup, IMarkupFormatter formatter)\r\n   at PreMailer.Net.PreMailer.MoveCssInline(Boolean removeStyleElements, String ignoreElements, String css, Boolean stripIdAndClassAttributes, Boolean removeComments)\r\n   

Removing the comment in the end solves the issue.

<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body></body>
</html>
@FlorianRappl
Copy link
Contributor

FlorianRappl commented Nov 22, 2016

From the dump you've shown it does not seem that parsing is the problem - rather the serialization. Can you confirm and show the code (not the document, i.e., present a MWE) that crashes?

Thanks!

@enkelmedia
Copy link
Author

I think that it might be when it's converted to a HtmlDocument?

@FlorianRappl
Copy link
Contributor

FlorianRappl commented Nov 22, 2016

Nope - there is no such process. It starts with an HtmlDocument and ends with an HtmlDocument. MWE to reproduce?

@FlorianRappl
Copy link
Contributor

Which version are you using? I can't reproduce the bug.

@enkelmedia
Copy link
Author

I'm using the latest version - but trough PreMailer.NET. Since the exception was trown from AngleSharp i figured that the issues was there. If my example with the comment works then the issue is in PreMailer.NET - sorry for that!

@FlorianRappl
Copy link
Contributor

I assume the error is in this line.

I've checked with the current code and everything seems to be fine here. My guess is that the problem indeed existed (and has to do with comments in general - independent of their position!), but is already gone due to some fix earlier in the process of v0.10.

@DaniilVeriga
Copy link

There is the same issue with a comment in the beginning: #610

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

No branches or pull requests

3 participants