Skip to content

Commit

Permalink
Add using()s around internal usage of IHtmlDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
mganss committed Jan 2, 2018
1 parent 40d0656 commit 58a7a75
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/HtmlSanitizer/HtmlSanitizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,13 @@ private static IEnumerable<INode> GetAllNodes(INode dom)
/// <returns>The sanitized HTML body fragment.</returns>
public string Sanitize(string html, string baseUrl = "", IMarkupFormatter outputFormatter = null)
{
var dom = SanitizeDom(html, baseUrl);
var output = dom.Body.ChildNodes.ToHtml(outputFormatter ?? OutputFormatter);
return output;
using (var dom = SanitizeDom(html, baseUrl))
{
var output = dom.Body.ChildNodes.ToHtml(outputFormatter ?? OutputFormatter);
return output;
}
}


/// <summary>
/// Sanitizes the specified HTML body fragment. If a document is given, only the body part will be returned.
/// </summary>
Expand Down Expand Up @@ -465,13 +466,15 @@ public IHtmlDocument SanitizeDom(string html, string baseUrl = "")
public string SanitizeDocument(string html, string baseUrl = "", IMarkupFormatter outputFormatter = null)
{
var parser = HtmlParserFactory();
var dom = parser.Parse(html);

DoSanitize(dom, dom.DocumentElement, baseUrl);
using (var dom = parser.Parse(html))
{
DoSanitize(dom, dom.DocumentElement, baseUrl);

var output = dom.ToHtml(outputFormatter ?? OutputFormatter);
var output = dom.ToHtml(outputFormatter ?? OutputFormatter);

return output;
return output;
}
}

/// <summary>
Expand Down

0 comments on commit 58a7a75

Please sign in to comment.