From 0b8b5d111900ffa2cf0a7d24095ee4e20721c137 Mon Sep 17 00:00:00 2001 From: Michael Ganss Date: Mon, 25 Sep 2023 15:55:11 +0200 Subject: [PATCH] Fix #469 --- src/HtmlSanitizer/HtmlSanitizer.cs | 2 +- test/HtmlSanitizer.Tests/Tests.cs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/HtmlSanitizer/HtmlSanitizer.cs b/src/HtmlSanitizer/HtmlSanitizer.cs index 978a07d..e51744d 100644 --- a/src/HtmlSanitizer/HtmlSanitizer.cs +++ b/src/HtmlSanitizer/HtmlSanitizer.cs @@ -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); diff --git a/test/HtmlSanitizer.Tests/Tests.cs b/test/HtmlSanitizer.Tests/Tests.cs index 2b77055..058521f 100644 --- a/test/HtmlSanitizer.Tests/Tests.cs +++ b/test/HtmlSanitizer.Tests/Tests.cs @@ -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 = @"
"; + var sanitizer = new HtmlSanitizer(); + var sanitized = sanitizer.Sanitize(html); + Assert.Equal(@"
", sanitized); + } }