Author: alanmc
Date: 2007-01-12 11:51:08 -0500 (Fri, 12 Jan 2007)
New Revision: 70930

Modified:
   trunk/bitsharp/src/MonoTorrent.Common/BEncode/BEncodedDictionary.cs
   trunk/bitsharp/src/MonoTorrent.Common/BEncode/BEncodedString.cs
Log:
Bugfix in BEncodedString class. They are now compared correctly in the 
CompareTo methods. Also bugfix in the dictionary class. I was adding the "key" 
element of the dictionary in a way which would have led to problems if the key 
wasn't valid UTF8.

Modified: trunk/bitsharp/src/MonoTorrent.Common/BEncode/BEncodedDictionary.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent.Common/BEncode/BEncodedDictionary.cs 
2007-01-12 16:29:18 UTC (rev 70929)
+++ trunk/bitsharp/src/MonoTorrent.Common/BEncode/BEncodedDictionary.cs 
2007-01-12 16:51:08 UTC (rev 70930)
@@ -136,13 +136,12 @@
                 while ((reader.PeekChar() != -1) && ((char)reader.PeekChar() 
!= 'e'))
                 {
                     key = (BEncodedString)BEncode.Decode(reader); ;     // 
keys have to be BEncoded strings
-                    if (oldkey != null)
-                        if (string.CompareOrdinal(oldkey.Text, key.Text) > 0) 
-                            throw new BEncodingException("Illegal 
BEncodedDictionary. The attributes are not ordered correctly");
-                    oldkey = key;
+                    if (oldkey != null && string.CompareOrdinal(oldkey.Text, 
key.Text) > 0) 
+                        throw new BEncodingException("Illegal 
BEncodedDictionary. The attributes are not ordered correctly");
                     
+                    oldkey = key;
                     value = BEncode.Decode(reader);                     // the 
value is a BEncoded value
-                    dictionary.Add(key.Text, value);
+                    dictionary.Add(key, value);
                 }
 
                 if (reader.ReadByte() != 'e')                                  
  // remove the trailing 'e'

Modified: trunk/bitsharp/src/MonoTorrent.Common/BEncode/BEncodedString.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent.Common/BEncode/BEncodedString.cs     
2007-01-12 16:29:18 UTC (rev 70929)
+++ trunk/bitsharp/src/MonoTorrent.Common/BEncode/BEncodedString.cs     
2007-01-12 16:51:08 UTC (rev 70930)
@@ -219,12 +219,12 @@
 
         public int CompareTo(BEncodedString other)
         {
-            return this.Text.CompareTo(other.Text);
+            return string.CompareOrdinal(this.Text, other.Text);
         }
 
         public int CompareTo(string other)
         {
-            return this.Text.CompareTo(other);
+            return string.CompareOrdinal(this.Text, other);
         }
         #endregion
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to