public GetSafeHtmlFragment ( string htmlText, string[]>.Dictionary |
||
htmlText | string | |
tagsWhiteList | string[]>.Dictionary | |
return | string |
public string GetSafeHtmlFragment(string htmlText, Dictionary<string, string[]> tagsWhiteList)
{
var html = new HtmlDocument();
html.OptionFixNestedTags = true;
html.OptionAutoCloseOnEnd = true;
html.OptionDefaultStreamEncoding = Encoding.UTF8;
html.LoadHtml(htmlText);
if(html == null)
return String.Empty;
Sanitize(new HtmlNodeWrapper(html.DocumentNode), tagsWhiteList);
return html.DocumentNode.InnerHtml;
}
public void MakeSureItSanitized(string htmlFragment, string message) { var target = new DefaultHtmlSanitizer(); var elementWhiteList = CreateElementWhiteList(); var actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList); if(htmlFragment != "See Below") StringAssert.AreNotEqualIgnoringCase(htmlFragment, actual, message); }