Skip to content

Commit

Permalink
Fix #469
Browse files Browse the repository at this point in the history
  • Loading branch information
mganss committed Sep 25, 2023
1 parent 1cf8ff0 commit 0b8b5d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/HtmlSanitizer/HtmlSanitizer.cs
Expand Up @@ -721,7 +721,7 @@ private void SanitizeStyleDeclaration(IElement element, ICssStyleDeclaration sty

foreach (var url in urls)
{
sb.Append(val, ix, url.Match.Index);
sb.Append(val, ix, url.Match.Index - ix);
sb.Append("url(");
sb.Append(url.Match.Groups[1].Value);
sb.Append(url.Url);
Expand Down
10 changes: 10 additions & 0 deletions test/HtmlSanitizer.Tests/Tests.cs
Expand Up @@ -3487,4 +3487,14 @@ public void VarUrlTest()
var sanitized = sanitizer.Sanitize(html);
Assert.Equal(html, sanitized);
}

[Fact]
public void Number469Test()
{
// see https://github.com/mganss/HtmlSanitizer/issues/469
var html = @"<div style=""height: 0; background-image: url('https://example.com/1.jpg'), url('https://example.com/2.jpg'), url('https://example.com/3.jpg'); display: none;""/>";
var sanitizer = new HtmlSanitizer();
var sanitized = sanitizer.Sanitize(html);
Assert.Equal(@"<div style=""height: 0; background-image: url(&quot;https://example.com/1.jpg&quot;), url(&quot;https://example.com/2.jpg&quot;), url(&quot;https://example.com/3.jpg&quot;); display: none""></div>", sanitized);
}
}

0 comments on commit 0b8b5d1

Please sign in to comment.