Updated UriHelper.FormatFlags.
[mono.git] / mcs / class / System / System / Uri.cs
index 83bcb2a8810458214180cace6f237b2359cf4943..5749967985ba77c32e188d7205f53bc06ff7eecf 100644 (file)
@@ -90,6 +90,17 @@ namespace System {
                private string cachedToString;
                private string cachedLocalPath;
                private int cachedHashCode;
+               
+#if NET_4_5
+               private static volatile bool s_IriParsing = true;
+#else
+               private static volatile bool s_IriParsing = false;
+#endif
+
+               public static bool IriParsing {
+                       get { return s_IriParsing; }
+                       set { s_IriParsing = value; }
+               }
 
 #if BOOTSTRAP_BASIC
                private static readonly string hexUpperChars = "0123456789ABCDEF";
@@ -112,7 +123,11 @@ namespace System {
                public static readonly string UriSchemeNntp = "nntp";
                public static readonly string UriSchemeNetPipe = "net.pipe";
                public static readonly string UriSchemeNetTcp = "net.tcp";
-               
+
+               internal static readonly string UriSchemeTelnet = "telnet";
+               internal static readonly string UriSchemeLdap = "ldap";
+               internal static readonly string UriSchemeUuid = "uuid";
+
                private static readonly string [] knownUriSchemes =
                {
                        UriSchemeFile,
@@ -463,13 +478,10 @@ namespace System {
                public string AbsoluteUri { 
                        get { 
                                EnsureAbsoluteUri ();
-                               if (cachedAbsoluteUri == null) {
-                                       cachedAbsoluteUri = GetLeftPart (UriPartial.Path);
-                                       if (query.Length > 0)
-                                               cachedAbsoluteUri += query;
-                                       if (fragment.Length > 0)
-                                               cachedAbsoluteUri += fragment;
-                               }
+
+                               if (cachedAbsoluteUri == null)
+                                       cachedAbsoluteUri = GetComponents (UriComponents.AbsoluteUri, UriFormat.UriEscaped);
+
                                return cachedAbsoluteUri;
                        } 
                }
@@ -1095,13 +1107,10 @@ namespace System {
                        if (cachedToString != null) 
                                return cachedToString;
 
-                       if (isAbsoluteUri) {
-                               cachedToString = Unescape (GetLeftPart (UriPartial.Path), true);
-                               AppendQueryAndFragment (ref cachedToString);
-                       } else {
-                               // Everything is contained in path in this case. 
-                               cachedToString = path;
-                       }
+                       if (isAbsoluteUri)
+                               cachedToString = parser.GetComponentsHelper (this, UriComponents.AbsoluteUri, UriHelper.ToStringUnescape);
+                       else
+                               cachedToString = UriHelper.FormatRelative (source, scheme, UriHelper.ToStringUnescape);
 
                        return cachedToString;
                }
@@ -1354,7 +1363,7 @@ namespace System {
 
                private bool SupportsQuery ()
                {
-                       return ((scheme != Uri.UriSchemeNntp) && (scheme != Uri.UriSchemeFtp) && (scheme != Uri.UriSchemeFile));
+                       return UriHelper.SupportsQuery (scheme);
                }
 
                //
@@ -1443,6 +1452,10 @@ namespace System {
                        
                        scheme = TryGetKnownUriSchemeInstance (scheme);
 
+                       var formatFlags = UriHelper.FormatFlags.None;
+                       if (UriHelper.HasCharactersToNormalize (uriString))
+                               formatFlags |= UriHelper.FormatFlags.HasUriCharactersToNormalize;
+
                        // from here we're practically working on uriString.Substring(startpos,endpos-startpos)
                        int startpos = pos + 1;
                        int endpos = uriString.Length;
@@ -1450,12 +1463,12 @@ namespace System {
                        // 8 fragment
                        pos = uriString.IndexOf ('#', startpos);
                        if (!IsUnc && pos != -1) {
-                               if (userEscaped)
-                                       fragment = uriString.Substring (pos);
-                               else
-                                       fragment = "#" + EscapeString (uriString.Substring (pos+1));
-
+                               fragment = uriString.Substring (pos);
                                endpos = pos;
+                               if (!userEscaped) {
+                                       fragment = "#" + UriHelper.FormatAbsolute(fragment.Substring (1), scheme, 
+                                               UriComponents.Fragment, UriFormat.UriEscaped, formatFlags);
+                               }
                        }
 
                        // special case: there is no query part for 'news'
@@ -1472,8 +1485,10 @@ namespace System {
                                if (pos != -1) {
                                        query = uriString.Substring (pos, endpos-pos);
                                        endpos = pos;
-                                       if (!userEscaped)
-                                               query = EscapeString (query);
+                                       if (!userEscaped){
+                                               query = "?" + UriHelper.FormatAbsolute(query.Substring (1), scheme, 
+                                                       UriComponents.Query, UriFormat.UriEscaped, formatFlags);
+                                       }
                                }
                        }
 
@@ -1780,7 +1795,7 @@ namespace System {
 
                // A variant of HexUnescape() which can decode multi-byte escaped
                // sequences such as (e.g.) %E3%81%8B into a single character
-               private static char HexUnescapeMultiByte (string pattern, ref int index, out char surrogate) 
+               internal static char HexUnescapeMultiByte (string pattern, ref int index, out char surrogate) 
                {
                        surrogate = char.MinValue;