Skip to content

Commit

Permalink
Fix #155
Browse files Browse the repository at this point in the history
  • Loading branch information
mganss committed Jan 17, 2019
1 parent f4eeace commit cabae35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/HtmlSanitizer/HtmlSanitizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ private void DoSanitize(IHtmlDocument dom, IElement context, string baseUrl = ""
}

// sanitize the style attribute
var oldStyleEmpty = string.IsNullOrEmpty(tag.GetAttribute("style"));
SanitizeStyle(tag, baseUrl);

var checkClasses = AllowedCssClasses != null;
Expand All @@ -564,9 +565,9 @@ private void DoSanitize(IHtmlDocument dom, IElement context, string baseUrl = ""
if (!tag.ClassList.Any())
RemoveAttribute(tag, attribute, RemoveReason.ClassAttributeEmpty);
}
else if (string.IsNullOrEmpty(attribute.Value))
else if (!oldStyleEmpty && attribute.Name == "style" && string.IsNullOrEmpty(attribute.Value))
{
tag.RemoveAttribute(attribute.Name);
RemoveAttribute(tag, attribute, RemoveReason.StyleAttributeEmpty);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/HtmlSanitizer/RemoveReason.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public enum RemoveReason
/// <summary>
/// The class attribute is empty
/// </summary>
ClassAttributeEmpty
ClassAttributeEmpty,
/// <summary>
/// The style attribute is empty
/// </summary>
StyleAttributeEmpty,
}
}

0 comments on commit cabae35

Please sign in to comment.