Fixed EscapeDataString and EscapeUriString behavior.
authorMarcos Henrich <marcos.henrich@xamarin.com>
Mon, 14 Jul 2014 09:07:50 +0000 (10:07 +0100)
committerMarcos Henrich <marcos.henrich@xamarin.com>
Mon, 14 Jul 2014 09:07:50 +0000 (10:07 +0100)
The methods have now the same behavior as .NET 4.5, 4.0 and 2.0.

mcs/class/System/System/Uri.cs

index 198d93d398b4db269d10790c883c3b4a4d6b6e1c..3d97cb4b58bc8096ba39cd5fa48423f3c962b3bd 100644 (file)
@@ -2091,19 +2091,19 @@ namespace System {
                //
                static bool NeedToEscapeDataChar (char b)
                {
-#if NET_4_0
-                       // .NET 4.0 follows RFC 3986 Unreserved Characters
-                       return !((b >= 'A' && b <= 'Z') ||
-                                (b >= 'a' && b <= 'z') ||
-                                (b >= '0' && b <= '9') ||
-                                b == '-' || b == '.' || b == '_' || b == '~');
-#else
+                       if (IriParsing) {
+                               // .NET 4.0 follows RFC 3986 Unreserved Characters
+                               return !((b >= 'A' && b <= 'Z') ||
+                                        (b >= 'a' && b <= 'z') ||
+                                        (b >= '0' && b <= '9') ||
+                                        b == '-' || b == '.' || b == '_' || b == '~');
+                       }
+
                        return !((b >= 'A' && b <= 'Z') ||
                                 (b >= 'a' && b <= 'z') ||
                                 (b >= '0' && b <= '9') ||
                                 b == '_' || b == '~' || b == '!' || b == '\'' ||
                                 b == '(' || b == ')' || b == '*' || b == '-' || b == '.');
-#endif
                }
                
                public static string EscapeDataString (string stringToEscape)
@@ -2145,24 +2145,14 @@ namespace System {
                        if ((b >= 'A' && b <= 'Z') || (b >= 'a' && b <= 'z') || (b >= '&' && b <= ';'))
                                return false;
 
-                       switch (b) {
-                       case '!':
-                       case '#':
-                       case '$':
-                       case '=':
-                       case '?':
-                       case '@':
-                       case '_':
-                       case '~':
+                       if ("!#$=?@_~".IndexOf(b) != -1)
+                               return false;
+
 #if NET_4_0
-                       // .NET 4.0 follows RFC 3986
-                       case '[':
-                       case ']':
+                       if ("[]".IndexOf(b) != -1)
+                               return !IriParsing;
 #endif
-                               return false;
-                       default:
-                               return true;
-                       }
+                       return true;
                }
                
                public static string EscapeUriString (string stringToEscape)