Skip to content

Commit

Permalink
Update to AngleSharp.Css 0.16.4
Browse files Browse the repository at this point in the history
Add HexColorTest
  • Loading branch information
mganss committed Feb 24, 2022
1 parent ea681df commit fb36156
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/HtmlSanitizer/HtmlSanitizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

<ItemGroup>
<PackageReference Include="AngleSharp" Version="[0.16.1]" />
<PackageReference Include="AngleSharp.Css" Version="[0.16.3]" />
<PackageReference Include="AngleSharp.Css" Version="[0.16.4]" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>

Expand Down
24 changes: 23 additions & 1 deletion test/HtmlSanitizer.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2898,7 +2898,7 @@ public void ThreadTest()
var waiting = numThreads;
var methods = typeof(HtmlSanitizerTests).GetTypeInfo().GetMethods()
.Where(m => m.GetCustomAttributes(typeof(Xunit.FactAttribute), false).Cast<Xunit.FactAttribute>().Any(f => f.Skip == null))
.Where(m => m.Name != "ThreadTest");
.Where(m => m.Name != "ThreadTest" && m.Name != "HexColorTest");
var threads = Shuffle(methods, random)
.Take(numThreads)
.Select(m => new Thread(() =>
Expand Down Expand Up @@ -3330,5 +3330,27 @@ public void StyleFormatterTest()

Assert.Equal(html, sanitized);
}

[Fact]
public void HexColorTest()
{
// see https://github.com/mganss/HtmlSanitizer/issues/330
var html = @"<p style=""color: black"">Text</p>";
var sanitizer = new HtmlSanitizer();

sanitizer.AllowedTags.Add("style");

AngleSharp.Css.Values.Color.UseHex = true;

var sanitized = sanitizer.Sanitize(html);

Assert.Equal(@"<p style=""color: #000000"">Text</p>", sanitized);

AngleSharp.Css.Values.Color.UseHex = false;

sanitized = sanitizer.Sanitize(html);

Assert.Equal(@"<p style=""color: rgba(0, 0, 0, 1)"">Text</p>", sanitized);
}
}
}

0 comments on commit fb36156

Please sign in to comment.