コード例 #1
0
 private bool isallow(HttpCookie cook)
 {
     if (cook != null)
     {
         if (cook.ToString() != "")
         {
             return true;
         }
     }
     return false;
 }
コード例 #2
0
		[Test] // bug #81333
		public void ToStringTest ()
		{
			HttpCookie cookie;

			cookie = new HttpCookie ("cookie1", "this x=y is the & first = cookie");
			Assert.AreEqual ("System.Web.HttpCookie", cookie.ToString (), "#A1");
			Assert.AreEqual ("this x=y is the & first = cookie", cookie.Value, "#A2");
			Assert.AreEqual (2, cookie.Values.Count, "#A3");
			Assert.AreEqual ("this x", cookie.Values.GetKey (0), "#A4");
			Assert.AreEqual ("y is the ", cookie.Values.Get (0), "#A5");
			Assert.AreEqual (" first ", cookie.Values.GetKey (1), "#A6");
			Assert.AreEqual (" cookie", cookie.Values.Get (1), "#A7");
			Assert.AreEqual ("this+x=y+is+the+&+first+=+cookie",
				cookie.Values.ToString (), "#A8");

			cookie = new HttpCookie ("cookie11", cookie.Values.ToString ());
			Assert.AreEqual ("System.Web.HttpCookie", cookie.ToString (), "#B1");
			Assert.AreEqual ("this+x=y+is+the+&+first+=+cookie", cookie.Value, "#B2");
			Assert.AreEqual (2, cookie.Values.Count, "#B3");
			Assert.AreEqual ("this+x", cookie.Values.GetKey (0), "#B4");
			Assert.AreEqual ("y+is+the+", cookie.Values.Get (0), "#B5");
			Assert.AreEqual ("+first+", cookie.Values.GetKey (1), "#B6");
			Assert.AreEqual ("+cookie", cookie.Values.Get (1), "#B7");
			Assert.AreEqual ("this%2bx=y%2bis%2bthe%2b&%2bfirst%2b=%2bcookie",
				cookie.Values.ToString (), "#B8");

			cookie = new HttpCookie ("cookie2");
			cookie.Values ["first"] = "hell=o = y";
			cookie.Values ["second"] = "the&re";
			cookie.Values ["third"] = "three";
			cookie.Values ["three-a"] = null;
			cookie.Values ["fourth"] = "last value";
			Assert.AreEqual ("System.Web.HttpCookie", cookie.ToString (), "#C1");
			Assert.AreEqual ("first=hell=o = y&second=the&re&third=three&three"
				+ "-a=&fourth=last value", cookie.Value, "#C2");
			Assert.AreEqual (5, cookie.Values.Count, "#C3");
			Assert.AreEqual ("first", cookie.Values.GetKey (0), "#C4");
			Assert.AreEqual ("hell=o = y", cookie.Values.Get (0), "#C5");
			Assert.AreEqual ("second", cookie.Values.GetKey (1), "#C6");
			Assert.AreEqual ("the&re", cookie.Values.Get (1), "#C7");
			Assert.AreEqual ("third", cookie.Values.GetKey (2), "#C8");
			Assert.AreEqual ("three", cookie.Values.Get (2), "#C9");
			Assert.AreEqual ("three-a", cookie.Values.GetKey (3), "#C10");
			Assert.IsNull (cookie.Values.Get (3), "#C11");
			Assert.AreEqual ("fourth", cookie.Values.GetKey (4), "#C12");
			Assert.AreEqual ("last value", cookie.Values.Get (4), "#C13");
			Assert.AreEqual ("first=hell%3do+%3d+y&second=the%26re&third=three"
				+ "&three-a=&fourth=last+value", cookie.Values.ToString (), "#C14");

			cookie = new HttpCookie ("cookie21", cookie.Values.ToString ());
			Assert.AreEqual ("System.Web.HttpCookie", cookie.ToString (), "#D1");
			Assert.AreEqual ("first=hell%3do+%3d+y&second=the%26re&third=three"
				+ "&three-a=&fourth=last+value", cookie.Value, "#D2");
			Assert.AreEqual (5, cookie.Values.Count, "#D3");
			Assert.AreEqual ("first", cookie.Values.GetKey (0), "#D4");
			Assert.AreEqual ("hell%3do+%3d+y", cookie.Values.Get (0), "#D5");
			Assert.AreEqual ("second", cookie.Values.GetKey (1), "#D6");
			Assert.AreEqual ("the%26re", cookie.Values.Get (1), "#D7");
			Assert.AreEqual ("third", cookie.Values.GetKey (2), "#D8");
			Assert.AreEqual ("three", cookie.Values.Get (2), "#D9");
			Assert.AreEqual ("three-a", cookie.Values.GetKey (3), "#D10");
			Assert.AreEqual ("three-a", cookie.Values.GetKey (3), "#D11");
			Assert.AreEqual ("fourth", cookie.Values.GetKey (4), "#D12");
			Assert.AreEqual ("last+value", cookie.Values.Get (4), "#D13");
			Assert.AreEqual ("first=hell%253do%2b%253d%2by&second=the%2526re&"
				+ "third=three&three-a=&fourth=last%2bvalue",
				cookie.Values.ToString (), "#D14");

			cookie = new HttpCookie ("cookie3", "this is & the x=y third = cookie");
			cookie.Values ["first"] = "hel&l=o =y";
			cookie.Values ["second"] = "there";
			Assert.AreEqual ("System.Web.HttpCookie", cookie.ToString (), "#E1");
			Assert.AreEqual ("this is & the x=y third = cookie&first=hel&l=o =y"
				+ "&second=there", cookie.Value, "#E2");
			Assert.AreEqual (4, cookie.Values.Count, "#E3");
			Assert.IsNull (cookie.Values.GetKey (0), "#E4");
			Assert.AreEqual ("this is ", cookie.Values.Get (0), "#E5");
			Assert.AreEqual (" the x", cookie.Values.GetKey (1), "#E6");
			Assert.AreEqual ("y third = cookie", cookie.Values.Get (1), "#E7");
			Assert.AreEqual ("first", cookie.Values.GetKey (2), "#E8");
			Assert.AreEqual ("hel&l=o =y", cookie.Values.Get (2), "#E9");
			Assert.AreEqual ("second", cookie.Values.GetKey (3), "#E10");
			Assert.AreEqual ("there", cookie.Values.Get (3), "#E11");
			Assert.AreEqual ("this+is+&+the+x=y+third+%3d+cookie&first=hel%26l"
				+ "%3do+%3dy&second=there", cookie.Values.ToString (), "#E12");

			cookie = new HttpCookie ("cookie31", cookie.Values.ToString ());
			Assert.AreEqual ("System.Web.HttpCookie", cookie.ToString (), "#F1");
			Assert.AreEqual ("this+is+&+the+x=y+third+%3d+cookie&first=hel%26l"
				+ "%3do+%3dy&second=there", cookie.Value, "#F2");
			Assert.AreEqual (4, cookie.Values.Count, "#F3");
			Assert.IsNull (cookie.Values.GetKey (0), "#F4");
			Assert.AreEqual ("this+is+", cookie.Values.Get (0), "#F5");
			Assert.AreEqual ("+the+x", cookie.Values.GetKey (1), "#F6");
			Assert.AreEqual ("y+third+%3d+cookie", cookie.Values.Get (1), "#F7");
			Assert.AreEqual ("first", cookie.Values.GetKey (2), "#F8");
			Assert.AreEqual ("hel%26l%3do+%3dy", cookie.Values.Get (2), "#F9");
			Assert.AreEqual ("second", cookie.Values.GetKey (3), "#F10");
			Assert.AreEqual ("there", cookie.Values.Get (3), "#F11");
			Assert.AreEqual ("this%2bis%2b&%2bthe%2bx=y%2bthird%2b%253d%2bcookie"
				+ "&first=hel%2526l%253do%2b%253dy&second=there",
				cookie.Values.ToString (), "#F12");

			cookie = new HttpCookie ("funkycookie", "`~!@#$%^&*()_+-=\\][{}|'\";:,<.>/?");
			Assert.AreEqual ("System.Web.HttpCookie", cookie.ToString (), "#G1");
			Assert.AreEqual ("`~!@#$%^&*()_+-=\\][{}|'\";:,<.>/?", cookie.Value, "#G2");
			Assert.AreEqual (2, cookie.Values.Count, "#G3");
			Assert.IsNull (cookie.Values.GetKey (0), "#G4");
			Assert.AreEqual ("`~!@#$%^", cookie.Values.Get (0), "#G5");
			Assert.AreEqual ("*()_+-", cookie.Values.GetKey (1), "#G6");
			Assert.AreEqual ("\\][{}|'\";:,<.>/?", cookie.Values.Get (1), "#G7");
			Assert.AreEqual ("%60%7e!%40%23%24%25%5e&*()_%2b-=%5c%5d%5b%7b%7d"
				+ "%7c'%22%3b%3a%2c%3c.%3e%2f%3f", cookie.Values.ToString (), "#G8");

			cookie = new HttpCookie ("funkycookie11", cookie.Values.ToString ());
			Assert.AreEqual ("System.Web.HttpCookie", cookie.ToString (), "#H1");
			Assert.AreEqual ("%60%7e!%40%23%24%25%5e&*()_%2b-=%5c%5d%5b%7b%7d"
				+ "%7c'%22%3b%3a%2c%3c.%3e%2f%3f", cookie.Value, "#H2");
			Assert.AreEqual (2, cookie.Values.Count, "#H3");
			Assert.IsNull (cookie.Values.GetKey (0), "#H4");
			Assert.AreEqual ("%60%7e!%40%23%24%25%5e", cookie.Values.Get (0), "#H5");
			Assert.AreEqual ("*()_%2b-", cookie.Values.GetKey (1), "#H6");
			Assert.AreEqual ("%5c%5d%5b%7b%7d%7c'%22%3b%3a%2c%3c.%3e%2f%3f",
				cookie.Values.Get (1), "#H7");
			Assert.AreEqual ("%2560%257e!%2540%2523%2524%2525%255e&*()_%252b-="
				+ "%255c%255d%255b%257b%257d%257c'%2522%253b%253a%252c%253c.%2"
				+ "53e%252f%253f", cookie.Values.ToString (), "#H8");

			cookie = new HttpCookie ("basic");
			cookie.Values ["one"] = "hello world";
			cookie.Values ["two"] = "a^2 + b^2 = c^2";
			cookie.Values ["three"] = "a & b";
			Assert.AreEqual ("System.Web.HttpCookie", cookie.ToString (), "#I1");
			Assert.AreEqual ("one=hello world&two=a^2 + b^2 = c^2&three=a & b",
				cookie.Value, "#I2");
			Assert.AreEqual (3, cookie.Values.Count, "#I3");
			Assert.AreEqual ("one", cookie.Values.GetKey (0), "#I4");
			Assert.AreEqual ("hello world", cookie.Values.Get (0), "#I5");
			Assert.AreEqual ("two", cookie.Values.GetKey (1), "#I6");
			Assert.AreEqual ("a^2 + b^2 = c^2", cookie.Values.Get (1), "#I7");
			Assert.AreEqual ("three", cookie.Values.GetKey (2), "#I8");
			Assert.AreEqual ("a & b", cookie.Values.Get (2), "#I9");
			Assert.AreEqual ("one=hello+world&two=a%5e2+%2b+b%5e2+%3d+c%5e2&"
				+ "three=a+%26+b", cookie.Values.ToString (), "#I10");

			HttpCookie cookie2 = new HttpCookie ("basic2");
			cookie2.Value = cookie.Values.ToString ();
			Assert.AreEqual ("System.Web.HttpCookie", cookie2.ToString (), "#J1");
			Assert.AreEqual ("one=hello+world&two=a%5e2+%2b+b%5e2+%3d+c%5e2&"
				+ "three=a+%26+b", cookie2.Value, "#J2");
			Assert.AreEqual (3, cookie2.Values.Count, "#J3");
			Assert.AreEqual ("one", cookie.Values.GetKey (0), "#J4");
			Assert.AreEqual ("hello world", cookie.Values.Get (0), "#J5");
			Assert.AreEqual ("two", cookie.Values.GetKey (1), "#J6");
			Assert.AreEqual ("a^2 + b^2 = c^2", cookie.Values.Get (1), "#J7");
			Assert.AreEqual ("three", cookie.Values.GetKey (2), "#J8");
			Assert.AreEqual ("a & b", cookie.Values.Get (2), "#J9");
			Assert.AreEqual ("one=hello%2bworld&two=a%255e2%2b%252b%2bb%255e2"
				+ "%2b%253d%2bc%255e2&three=a%2b%2526%2bb",
				cookie2.Values.ToString (), "#J10");
		}