Updated UriHelper.FormatFlags.
[mono.git] / mcs / class / System / System / Uri.cs
index 0a4f07aff17e52d1dee8849593b7df226a1f18da..5749967985ba77c32e188d7205f53bc06ff7eecf 100644 (file)
@@ -478,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;
                        } 
                }
@@ -1110,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;
                }
@@ -1458,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;
@@ -1465,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'
@@ -1487,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);
+                                       }
                                }
                        }