Skip to content

Commit 0b8b5d1

Browse files
committed
Fix #469
1 parent 1cf8ff0 commit 0b8b5d1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/HtmlSanitizer/HtmlSanitizer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ private void SanitizeStyleDeclaration(IElement element, ICssStyleDeclaration sty
721721

722722
foreach (var url in urls)
723723
{
724-
sb.Append(val, ix, url.Match.Index);
724+
sb.Append(val, ix, url.Match.Index - ix);
725725
sb.Append("url(");
726726
sb.Append(url.Match.Groups[1].Value);
727727
sb.Append(url.Url);

test/HtmlSanitizer.Tests/Tests.cs

+10
Original file line numberDiff line numberDiff line change
@@ -3487,4 +3487,14 @@ public void VarUrlTest()
34873487
var sanitized = sanitizer.Sanitize(html);
34883488
Assert.Equal(html, sanitized);
34893489
}
3490+
3491+
[Fact]
3492+
public void Number469Test()
3493+
{
3494+
// see https://github.com/mganss/HtmlSanitizer/issues/469
3495+
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;""/>";
3496+
var sanitizer = new HtmlSanitizer();
3497+
var sanitized = sanitizer.Sanitize(html);
3498+
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);
3499+
}
34903500
}

0 commit comments

Comments
 (0)