Example #1
0
        // Hack to work around improper OO design
        protected override void Render(HtmlTextWriter output)
        {
            Uri url = null;

            try
            {
                url = new Uri(this.NavigateUrl);

                if (url.Scheme == Uri.UriSchemeHttp ||
                    url.Scheme == Uri.UriSchemeHttps ||
                    url.Scheme == Uri.UriSchemeMailto)
                {
                    string _reformText = Text;

                    NavigateUrl = url.ToString();
                    Text        = Reform.HtmlEncode(_reformText);

                    base.Render(output);

                    Text = _reformText;
                }
                else
                {
                    throw new ReformUrlException(url, "IOActive.Reform.ReformHyperLink::Render()");
                }
            }
            catch (UriFormatException)
            {
                throw new ReformUrlException(null, this.NavigateUrl);
            }
        }
Example #2
0
        protected override void Render(HtmlTextWriter output)
        {
            string _reformText = Text;

            Text = Reform.HtmlEncode(_reformText);
            base.Render(output);
            Text = _reformText;
        }
Example #3
0
        public void HtmlEncodeDefault()
        {
            // Usual stuff
            Assert.AreEqual("default",
                            Reform.HtmlEncode(null, "default"), "Checking default");

            // Non encoded characters
            Assert.AreEqual("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.",
                            Reform.HtmlEncode(null, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,."), "Non encoding chars via default");
            // Usual suspects
            Assert.AreEqual("<>&"",
                            Reform.HtmlEncode(null, "<>&\""), "Usual suspects via default");
            // Other characters
            Assert.AreEqual("&#96;&#126;&#33;&#64;&#35;&#36;&#37;&#94;&#38;&#42;&#40;&#41;&#95;&#43;&#61;&#45;&#123;&#125;&#124;&#92;&#93;&#91;&#58;&#59;&#39;&#47;&#63;&#62;&#60;",
                            Reform.HtmlEncode(null, "`~!@#$%^&*()_+=-{}|\\][:;'/?><"), "Punctuation via default");
            // Unicode characters
            StringBuilder toEncode   = new StringBuilder(6000);
            StringBuilder encodedStr = new StringBuilder(42000);

            for (uint i = 127; i < 6000; i++)
            {
                toEncode.Append((char)i);
                encodedStr.Append("&#").Append((int)i).Append(';');
            }
            Assert.AreEqual(encodedStr.ToString(),
                            Reform.HtmlEncode(null, toEncode.ToString()), "Unicode characters to 6000 via default");

            // The following are sanity checks

            // Non encoded characters
            Assert.AreEqual("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.",
                            Reform.HtmlEncode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0987654321 ,.", "default"), "Non encoding chars");
            // Usual suspects
            Assert.AreEqual("&#60;&#62;&#38;&#34;",
                            Reform.HtmlEncode("<>&\"", "default"), "Usual suspects");
            // Other characters
            Assert.AreEqual("&#96;&#126;&#33;&#64;&#35;&#36;&#37;&#94;&#38;&#42;&#40;&#41;&#95;&#43;&#61;&#45;&#123;&#125;&#124;&#92;&#93;&#91;&#58;&#59;&#39;&#47;&#63;&#62;&#60;",
                            Reform.HtmlEncode("`~!@#$%^&*()_+=-{}|\\][:;'/?><", "default"), "Punctuation");
            // Unicode characters
            toEncode   = new StringBuilder(6000);
            encodedStr = new StringBuilder(42000);
            for (uint i = 127; i < 6000; i++)
            {
                toEncode.Append((char)i);
                encodedStr.Append("&#").Append((int)i).Append(';');
            }
            Assert.AreEqual(encodedStr.ToString(),
                            Reform.HtmlEncode(toEncode.ToString(), "default"), "Unicode characters to 6000");
        }