本文整理汇总了C#中Security.SanitizeHTML方法的典型用法代码示例。如果您正苦于以下问题:C# Security.SanitizeHTML方法的具体用法?C# Security.SanitizeHTML怎么用?C# Security.SanitizeHTML使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Security
的用法示例。
在下文中一共展示了Security.SanitizeHTML方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSanitizeHTMLTagIsFirst
public void TestSanitizeHTMLTagIsFirst()
{
//arrange
var secure = new Security();
//act
var result = secure.SanitizeHTML("<script>evil</script><b>hello</b>");
//assert
Assert.AreEqual(@"<script>evil</script><b>hello</b>", result);
}
示例2: TestSanitizeHTMLNoUnsafe
public void TestSanitizeHTMLNoUnsafe()
{
//arrange
var secure = new Security();
//act
var result = secure.SanitizeHTML("<b>hello</b><body>evil</body>");
//assert
Assert.AreEqual(@"<b>hello</b><body>evil</body>", result);
}
示例3: SanitizeHTMLTest
public void SanitizeHTMLTest()
{
// Arrange - Create an instance of any class that you need to test
var htmlSanitizer = new Security();
// Act - Use this section to perform the action that you are testing. Typically, you call a method in this section.
var htmlStr = "<b>hello</b><script>evil</script>"; // Initialize string variable with string content
var result = htmlSanitizer.SanitizeHTML(htmlStr); // Run test method to ensure proper functioning
// Assert - Use this section to assert that a certain condition is true.
Assert.AreNotEqual(result, "<b>hello</b><script>evil</script>");
// Assert.AreEqual(result, "<b>hello</b><script>evil</script>");
}
示例4: TestTags
public void TestTags()
{
// Arrange
var security = new Security();
//allowed tags
var whitelist = new List<string>();
whitelist.Add("<b>");
whitelist.Add("</b>");
whitelist.Add("<p>");
whitelist.Add("</p>");
whitelist.Add("<table>");
whitelist.Add("</table>");
whitelist.Add("<ul>");
whitelist.Add("</ul>");
whitelist.Add("<ol>");
whitelist.Add("</ol>");
whitelist.Add("<li>");
whitelist.Add("</li>");
whitelist.Add("<tr>");
whitelist.Add("</tr>");
whitelist.Add("<td>");
whitelist.Add("</td>");
whitelist.Add("<th>");
whitelist.Add("</th>");
whitelist.Add("<h1>");
whitelist.Add("</h1>");
whitelist.Add("<h2>");
whitelist.Add("</h2>");
whitelist.Add("<h3>");
whitelist.Add("</h3>");
whitelist.Add("<h4>");
whitelist.Add("</h4>");
whitelist.Add("<h5>");
whitelist.Add("</h5>");
whitelist.Add("<h6>");
whitelist.Add("</h6>");
string testing = @"<></> <> </> <img/> <script></script><span><div>text test</div></span> <a href=""></a>";
string correct = @"<></> <> </> <img/> <script></script><span><div>text test</div></span> <a href=""></a>";
// Act
var result = security.SanitizeHTML(testing, whitelist);
// Assert
Assert.AreNotEqual(testing, result);
Assert.AreEqual(correct, result);
}