public void TestUrlEncodedStream() { string [][] charsets = new string[][] { new string[] { StringUtil.__ISO_8859_1, null }, new string[] { StringUtil.__ISO_8859_1, StringUtil.__ISO_8859_1 }, new string[] { StringUtil.__UTF8, StringUtil.__UTF8 }, new string[] { StringUtil.__UTF16, StringUtil.__UTF16 }, }; for (int i = 0; i < charsets.Length; i++) { MemoryStream input = new MemoryStream(Encoding.GetEncoding(charsets[i][0]).GetBytes("name\n=value+%30&name1=&name2&n\u00e3me3=value+3")); MultiMap <string> m = new MultiMap <string>(); UrlEncoded.DecodeTo(input, m, charsets[i][1], -1); Log.Info(m.ToString()); Assert.AreEqual(4, m.Count, i + " stream length"); Assert.AreEqual("value 0", m.GetString("name\n"), i + " stream name\\n"); Assert.AreEqual("", m.GetString("name1"), i + " stream name1"); Assert.AreEqual("", m.GetString("name2"), i + " stream name2"); Assert.AreEqual("value 3", m.GetString("n\u00e3me3"), i + " stream n\u00e3me3"); } try { byte[] bytes = Encoding.GetEncoding("Shift_JIS").GetBytes("name=%83e%83X%83g"); MemoryStream in2 = new MemoryStream(); in2.Write(bytes, 0, bytes.Length); MultiMap <string> m2 = new MultiMap <string>(); UrlEncoded.DecodeTo(in2, m2, "Shift_JIS", -1); Assert.AreEqual(1, m2.Count, "stream length"); Assert.AreEqual("\u30c6\u30b9\u30c8", m2.GetString("name"), "stream name"); } catch (ArgumentException) { Assert.IsTrue(true, "Charset Shift_JIS not supported by CLR"); } }
public void TestUrlEncodedStream() { string [][] charsets = new string[][] { new string[] {StringUtil.__ISO_8859_1,null}, new string[] {StringUtil.__ISO_8859_1,StringUtil.__ISO_8859_1}, new string[] {StringUtil.__UTF8,StringUtil.__UTF8}, new string[] {StringUtil.__UTF16,StringUtil.__UTF16}, }; for (int i=0;i<charsets.Length;i++) { MemoryStream input = new MemoryStream(Encoding.GetEncoding(charsets[i][0]).GetBytes("name\n=value+%30&name1=&name2&n\u00e3me3=value+3")); MultiMap<string> m = new MultiMap<string>(); UrlEncoded.DecodeTo(input, m, charsets[i][1], -1); Log.Info(m.ToString()); Assert.AreEqual(4, m.Count, i + " stream length"); Assert.AreEqual("value 0", m.GetString("name\n"), i + " stream name\\n"); Assert.AreEqual("", m.GetString("name1"), i + " stream name1"); Assert.AreEqual("", m.GetString("name2"), i + " stream name2"); Assert.AreEqual("value 3", m.GetString("n\u00e3me3"), i + " stream n\u00e3me3"); } try { byte[] bytes = Encoding.GetEncoding("Shift_JIS").GetBytes("name=%83e%83X%83g"); MemoryStream in2 = new MemoryStream(); in2.Write(bytes, 0, bytes.Length); MultiMap<string> m2 = new MultiMap<string>(); UrlEncoded.DecodeTo(in2, m2, "Shift_JIS", -1); Assert.AreEqual(1, m2.Count, "stream length"); Assert.AreEqual("\u30c6\u30b9\u30c8", m2.GetString("name"), "stream name"); } catch (ArgumentException) { Assert.IsTrue(true, "Charset Shift_JIS not supported by CLR"); } }