예제 #1
0
        private static string ValidateString(string s)
        {
            int num1;

            if (HtmlUtil.ContainsHtml(s, out num1))
            {
                string text1 = "";
                int    num2  = num1 - 10;
                if (num2 <= 0)
                {
                    num2 = 0;
                }
                else
                {
                    text1 = text1 + "...";
                }
                int num3 = num1 + 20;
                if (num3 >= s.Length)
                {
                    num3  = s.Length;
                    text1 = text1 + s.Substring(num2, num3 - num2);
                }
                else
                {
                    text1 = text1 + s.Substring(num2, num3 - num2) + "...";
                }

                return(text1);
            }
            return(null);
        }
예제 #2
0
        public void TestContainsHtml()
        {
            Assert.IsFalse(HtmlUtil.ContainsHtml(null));
            Assert.IsFalse(HtmlUtil.ContainsHtml(""));
            Assert.IsFalse(HtmlUtil.ContainsHtml("whatever"));
            Assert.IsTrue(HtmlUtil.ContainsHtml("<html><body>text</body></html>"));
            Assert.IsTrue(HtmlUtil.ContainsHtml("<something"));

            // Case 1718 - &# shouldn't be detected as "script" on its own, but encoded HTML still should be.
            Assert.IsFalse(HtmlUtil.ContainsHtml("and some &#12 escaping"));
            Assert.IsTrue(HtmlUtil.ContainsHtml("and some &lt;b&gt; escaping"));
            Assert.IsTrue(HtmlUtil.ContainsHtml("and some &#x3c;b&#x3e; escaping"));
        }
예제 #3
0
 private static void TestXss(string xss)
 {
     Assert.IsTrue(HtmlUtil.ContainsScript(xss));
     Assert.IsTrue(HtmlUtil.ContainsHtml(xss));
 }