[Mono-bugs] [Bug 81330][Nor] New - HttpCookie.Values.ToString() different from ms.net [w/ fix]
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Sat Apr 7 00:39:27 EDT 2007
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by mmorano at mikeandwan.us.
http://bugzilla.ximian.com/show_bug.cgi?id=81330
--- shadow/81330 2007-04-07 00:39:27.000000000 -0400
+++ shadow/81330.tmp.17253 2007-04-07 00:39:27.000000000 -0400
@@ -0,0 +1,101 @@
+Bug#: 81330
+Product: Mono: Class Libraries
+Version: 1.2
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: Sys.Web
+AssignedTo: mhabersack at novell.com
+ReportedBy: mmorano at mikeandwan.us
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: HttpCookie.Values.ToString() different from ms.net [w/ fix]
+
+Currently, if you compare the method identified above, the results in mono
+are quite different from the results in ms. This has more than cosmetic
+issues, as MS can roundtrip the cookie, but currently mono can not. For
+example, in ms, you can do something like:
+
+HttpCookie cookie = new HttpCookie("mycookie", "my value for the cookie");
+HttpCookie cookie2 = new HttpCookie("my2", cookie.Values.ToString())
+
+and the contents of both cookies are equivalent. This can work for simple
+cookies, but if cookies contain more complex content, it needs to properly
+be encoded so that this round tripping is possible.
+
+The following patch addresses the issue to get the results much closer to
+the MS implementation.
+
+
+Index: System.Web/HttpCookie.cs
+===================================================================
+--- System.Web/HttpCookie.cs (revision 75493)
++++ System.Web/HttpCookie.cs (working copy)
+@@ -188,12 +188,12 @@
+ foreach (string kv in components){
+ int pos = kv.IndexOf ('=');
+ if (pos == -1){
+- values.Add (null, kv);
++ values.Set (null,
+HttpUtility.UrlDecode(kv));
+ } else {
+ string key =
+kv.Substring (0, pos);
+ string val =
+kv.Substring (pos+1);
+
+- values.Add (key, val);
++ values.Set
+(HttpUtility.UrlDecode(key), HttpUtility.UrlDecode(val));
+ }
+ }
+ }
+@@ -241,8 +241,12 @@
+ if (!first_key)
+ builder.Append ("&");
+
++ string[] vals = GetValues (key);
++ if(vals == null)
++ vals = new string[0];
++
+ bool first_val = true;
+- foreach (string v in GetValues (key)) {
++ foreach (string v in vals) {
+ if (!first_val)
+ builder.Append ("&");
+
+@@ -250,7 +254,9 @@
+ builder.Append (key);
+ builder.Append ("=");
+ }
+- builder.Append (v);
++ if(v != null)
++ builder.Append (v);
++
+ first_val = false;
+ }
+ first_key = false;
+@@ -268,10 +274,14 @@
+ if (this.IsReadOnly)
+ throw new NotSupportedException
+("Collection is read-only");
+
+- if (name == null)
++ if (name == null) {
+ Clear();
++ name = string.Empty;
++ }
++ if (value == null)
++ value = string.Empty;
+
+- base.Set (name, value);
++ base.Set (HttpUtility.UrlEncode(name),
+HttpUtility.UrlEncode(value));
+ }
+ }
+ }
More information about the mono-bugs
mailing list