Example #1
0
        public void HtmlEncodeFormatString()
        {
            string formatString = "<script>alert ('{0}');</script>";
            var    bf           = new PokerBoundField();

            Assert.IsTrue(bf.HtmlEncodeFormatString, "#A1-2");
            Assert.IsTrue(bf.HtmlEncode, "#A1-2");
            Assert.IsTrue(bf.DoSupportsHtmlEncode, "#A1-3");

            bf.DataFormatString = formatString;
#if NET_4_0
            Assert.AreEqual("&lt;script&gt;alert (&#39;&lt;test&gt;&#39;);&lt;/script&gt;", bf.DoFormatDataValue("<test>", true), "#A2");
#else
            Assert.AreEqual("&lt;script&gt;alert ('&lt;test&gt;');&lt;/script&gt;", bf.DoFormatDataValue("<test>", true), "#A2");
#endif
            Assert.AreEqual(String.Format(formatString, "<test>"), bf.DoFormatDataValue("<test>", false), "#A3");

            bf.HtmlEncodeFormatString = false;
            Assert.AreEqual("<script>alert ('&lt;test&gt;');</script>", bf.DoFormatDataValue("<test>", true), "#A4");

            var ec = new EncodingTest();
            bf.HtmlEncodeFormatString = true;
#if NET_4_0
            Assert.AreEqual("&lt;script&gt;alert (&#39;&lt;EncodingTest&gt;&amp;&#39;);&lt;/script&gt;", bf.DoFormatDataValue(ec, true), "#A4");
#else
            Assert.AreEqual("&lt;script&gt;alert ('&lt;EncodingTest&gt;&amp;');&lt;/script&gt;", bf.DoFormatDataValue(ec, true), "#A4");
#endif
        }
Example #2
0
		public void HtmlEncodeFormatString ()
		{
			string formatString = "<script>alert ('{0}');</script>"; 
			var bf = new PokerBoundField ();

			Assert.IsTrue (bf.HtmlEncodeFormatString, "#A1-2");
			Assert.IsTrue (bf.HtmlEncode, "#A1-2");
			Assert.IsTrue (bf.DoSupportsHtmlEncode, "#A1-3");

			bf.DataFormatString = formatString;
#if NET_4_0
			Assert.AreEqual ("&lt;script&gt;alert (&#39;&lt;test&gt;&#39;);&lt;/script&gt;", bf.DoFormatDataValue ("<test>", true), "#A2");
#else
			Assert.AreEqual ("&lt;script&gt;alert ('&lt;test&gt;');&lt;/script&gt;", bf.DoFormatDataValue ("<test>", true), "#A2");
#endif
			Assert.AreEqual (String.Format (formatString, "<test>"), bf.DoFormatDataValue ("<test>", false), "#A3");

			bf.HtmlEncodeFormatString = false;
			Assert.AreEqual ("<script>alert ('&lt;test&gt;');</script>", bf.DoFormatDataValue ("<test>", true), "#A4");

			var ec = new EncodingTest ();
			bf.HtmlEncodeFormatString = true;
#if NET_4_0
			Assert.AreEqual ("&lt;script&gt;alert (&#39;&lt;EncodingTest&gt;&amp;&#39;);&lt;/script&gt;", bf.DoFormatDataValue (ec, true), "#A4");
#else
			Assert.AreEqual ("&lt;script&gt;alert ('&lt;EncodingTest&gt;&amp;');&lt;/script&gt;", bf.DoFormatDataValue (ec, true), "#A4");
#endif
		}