[Mono-bugs] [Bug 81333][Nor] New - HttpCookie.Values.ToString() different from MS [w/ fix]

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Sat Apr 7 11:49:35 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=81333

--- shadow/81333	2007-04-07 11:49:35.000000000 -0400
+++ shadow/81333.tmp.29543	2007-04-07 11:49:35.000000000 -0400
@@ -0,0 +1,92 @@
+Bug#: 81333
+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 [w/ fix]
+
+This is a correction to a previous fix submitted in bug #81330, which I
+marked invalid after finding it did not satisfy all conditions.  This
+second attempt corrects the original so that it now properly matches the
+output of MS.  Thia also addresses a case where an exception is raised from
+a null value in the cookie value collection.
+
+The formatting is important for more than cosmetic reasons, as it more
+correctly can roundtrip a cookie now (cookie -> string -> cookie).  With
+the patch the result is also "expected" in that this is exactly what the ms
+runtime spits out.
+
+Honestly, it seems like there could still be improvements to support
+roundtripping as the attached test case will show, but did not implement so
+that we are consistent w/ ms.net.
+
+Here is the patch to address this:
+
+Index: System.Web/HttpCookie.cs
+===================================================================
+--- System.Web/HttpCookie.cs    (revision 75493)
++++ System.Web/HttpCookie.cs    (working copy)
+@@ -178,7 +178,7 @@
+ 
+                public string Value {
+                        get {
+-                               return values.ToString ();
++                               return
+HttpUtility.UrlDecode(values.ToString ());
+                        }
+                        set {
+                                values.Clear ();
+@@ -241,16 +241,22 @@
+                                        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 ("&");
+ 
+                                                if (key != null) {
+-                                                       builder.Append (key);
++                                                       builder.Append
+(HttpUtility.UrlEncode(key));
+                                                        builder.Append ("=");
+                                                }
+-                                               builder.Append (v);
++                                               if(v != null)
++                                                       builder.Append
+(HttpUtility.UrlEncode(v));
++
+                                                first_val = false;
+                                        }
+                                        first_key = false;
+@@ -268,8 +274,12 @@
+                                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);
+                        }


More information about the mono-bugs mailing list