public void TestHtmlDecode() { const string encoded = "<£€¢¥ ©®>"; const string expected = "<£€¢¥\u00a0©®>"; var decoded = HtmlUtils.HtmlDecode(encoded); Assert.AreEqual(expected, decoded); }
static void AssertHtmlEncode(string text, string expected) { string encoded, decoded; encoded = HtmlUtils.HtmlEncode(text); Assert.AreEqual(expected, encoded, "HtmlEncode(string)"); encoded = HtmlUtils.HtmlEncode(text, 0, text.Length); Assert.AreEqual(expected, encoded, "HtmlEncode(string,int,int)"); encoded = HtmlUtils.HtmlEncode(text.ToCharArray(), 0, text.Length); Assert.AreEqual(expected, encoded, "HtmlEncode(char[],int,int)"); using (var writer = new StringWriter()) { HtmlUtils.HtmlEncode(writer, text); encoded = writer.ToString(); Assert.AreEqual(expected, encoded, "HtmlEncode(TextWriter,string)"); } using (var writer = new StringWriter()) { HtmlUtils.HtmlEncode(writer, text, 0, text.Length); encoded = writer.ToString(); Assert.AreEqual(expected, encoded, "HtmlEncode(TextWriter,string,int,int)"); } using (var writer = new StringWriter()) { HtmlUtils.HtmlEncode(writer, text.ToCharArray(), 0, text.Length); encoded = writer.ToString(); Assert.AreEqual(expected, encoded, "HtmlEncode(TextWriter,char[],int,int)"); } decoded = HtmlUtils.HtmlDecode(encoded); Assert.AreEqual(text, decoded, "HtmlDecode(string)"); decoded = HtmlUtils.HtmlDecode(encoded, 0, encoded.Length); Assert.AreEqual(text, decoded, "HtmlDecode(string,int,int)"); using (var writer = new StringWriter()) { HtmlUtils.HtmlDecode(writer, encoded); decoded = writer.ToString(); Assert.AreEqual(text, decoded, "HtmlDecode(TextWriter,string)"); } using (var writer = new StringWriter()) { HtmlUtils.HtmlDecode(writer, encoded, 0, encoded.Length); decoded = writer.ToString(); Assert.AreEqual(text, decoded, "HtmlDecode(TextWriter,string,int,int)"); } }
public ushort[] Parse(string htmlRow) { List <ushort> dexNumbers = new List <ushort>(); Regex rgx = new Regex("#([0-9]{3})"); var matches = rgx.Matches(HtmlUtils.HtmlDecode(htmlRow)); foreach (Match match in matches) { dexNumbers.Add(ushort.Parse(match.Groups[1].ToString())); } return(dexNumbers.ToArray()); }
public static JsonMessage HtmlDecode(string text) { JsonMessage jsonMessage = new JsonMessage(); if (string.IsNullOrEmpty(text)) { jsonMessage.Flag = false; jsonMessage.Message = "解码内容不能为空"; return(jsonMessage); } try { jsonMessage.Flag = true; jsonMessage.Data = HtmlUtils.HtmlDecode(text); } catch (Exception ex) { jsonMessage.Flag = false; jsonMessage.Message = ex.Message; } return(jsonMessage); }
public void TestArgumentExceptions() { var writer = new StringWriter(); const string text = "text"; // HtmlAttributeEncode Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlAttributeEncode(null)); Assert.Throws <ArgumentException> (() => HtmlUtils.HtmlAttributeEncode(text, 'x')); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlAttributeEncode(null, text)); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlAttributeEncode(writer, null)); Assert.Throws <ArgumentException> (() => HtmlUtils.HtmlAttributeEncode(writer, text, 'x')); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlAttributeEncode((string)null, 0, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlAttributeEncode(text, -1, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlAttributeEncode(text, 0, text.Length + 1)); Assert.Throws <ArgumentException> (() => HtmlUtils.HtmlAttributeEncode(text, 0, text.Length, 'x')); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlAttributeEncode((char[])null, 0, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlAttributeEncode(text.ToCharArray(), -1, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlAttributeEncode(text.ToCharArray(), 0, text.Length + 1)); Assert.Throws <ArgumentException> (() => HtmlUtils.HtmlAttributeEncode(text.ToCharArray(), 0, text.Length, 'x')); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlAttributeEncode(null, text, 0, text.Length)); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlAttributeEncode(writer, (string)null, 0, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlAttributeEncode(writer, text, -1, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlAttributeEncode(writer, text, 0, text.Length + 1)); Assert.Throws <ArgumentException> (() => HtmlUtils.HtmlAttributeEncode(writer, text, 0, text.Length, 'x')); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlAttributeEncode(null, text.ToCharArray(), 0, text.Length)); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlAttributeEncode(writer, (char[])null, 0, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlAttributeEncode(writer, text.ToCharArray(), -1, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlAttributeEncode(writer, text.ToCharArray(), 0, text.Length + 1)); Assert.Throws <ArgumentException> (() => HtmlUtils.HtmlAttributeEncode(writer, text.ToCharArray(), 0, text.Length, 'x')); // HtmlEncode Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlEncode(null)); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlEncode(null, text)); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlEncode(writer, null)); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlEncode((string)null, 0, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlEncode(text, -1, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlEncode(text, 0, text.Length + 1)); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlEncode((char[])null, 0, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlEncode(text.ToCharArray(), -1, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlEncode(text.ToCharArray(), 0, text.Length + 1)); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlEncode(null, text, 0, text.Length)); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlEncode(writer, (string)null, 0, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlEncode(writer, text, -1, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlEncode(writer, text, 0, text.Length + 1)); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlEncode(null, text.ToCharArray(), 0, text.Length)); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlEncode(writer, (char[])null, 0, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlEncode(writer, text.ToCharArray(), -1, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlEncode(writer, text.ToCharArray(), 0, text.Length + 1)); // HtmlDecode Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlDecode(null)); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlDecode(null, text)); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlDecode(writer, null)); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlDecode(null, 0, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlDecode(text, -1, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlDecode(text, 0, text.Length + 1)); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlDecode(null, text, 0, text.Length)); Assert.Throws <ArgumentNullException> (() => HtmlUtils.HtmlDecode(writer, null, 0, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlDecode(writer, text, -1, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => HtmlUtils.HtmlDecode(writer, text, 0, text.Length + 1)); }
public string Parse(string htmlSingleRowInput) { var nameColumn = HtmlUtils.GetSingleHtmlNode(htmlSingleRowInput, "./tr/td[3]"); return(HtmlUtils.HtmlDecode(nameColumn.SelectSingleNode(".//a").InnerText.ToLower())); }