// 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); } }
protected override void Render(HtmlTextWriter output) { string _reformText = Text; Text = Reform.HtmlEncode(_reformText); base.Render(output); Text = _reformText; }
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("`~!@#$%^&*()_+=-{}|\][:;'/?><", 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("<>&"", Reform.HtmlEncode("<>&\"", "default"), "Usual suspects"); // Other characters Assert.AreEqual("`~!@#$%^&*()_+=-{}|\][:;'/?><", 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"); }