Skip to content

Commit

Permalink
Add test to indicate AngleSharp is the issue with the html entity enc…
Browse files Browse the repository at this point in the history
…oding

Also found out turning on IsNotConsumingCharacterReferences does not fix the issue and causes a strange result:

Expected: <html><head></head><body><div>&lt;&amp;&gt;&nbsp;&copy;</div></body></html>
Actual:   <html><head></head><body><div>&amp;lt;&amp;amp;&amp;gt;&amp;nbsp;&amp;copy;</div></body></html>
  • Loading branch information
jasekiw committed Sep 15, 2023
1 parent 1f19019 commit d6ad7af
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions PreMailer.Net/PreMailer.Net.Tests/AngleSharpTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using AngleSharp;
using AngleSharp.Html.Parser;
using Xunit;

namespace PreMailer.Net.Tests;

public class AngleSharpTests
{
[Fact]
public void HtmlDocument_ToHtml_ShouldNotEffectHtmlEntities()
{
string htmlEncoded = "&lt;&amp;&gt;&nbsp;&copy;";
string input = $"<html><head></head><body><div>{htmlEncoded}</div></body></html>";
var document = new HtmlParser(new HtmlParserOptions()
{
IsNotConsumingCharacterReferences = true
}).ParseDocument(input);
var output = document.ToHtml();
Assert.Equal<object>(input, output); // use object to get full string output
}
}

0 comments on commit d6ad7af

Please sign in to comment.