Merge pull request #1222 from LogosBible/uri-trycreate
[mono.git] / mcs / class / System / System / Uri.cs
index 5a6b930d40201ba539cdf7809e3bb523b38786a1..a1417e99527c0bd59f0befff9246110310ab4080 100644 (file)
@@ -140,9 +140,7 @@ namespace System {
 
                static Uri ()
                {
-#if NET_4_5
                        IriParsing = true;
-#endif
 
                        var iriparsingVar = Environment.GetEnvironmentVariable ("MONO_URI_IRIPARSING");
                        if (iriparsingVar == "true")
@@ -342,12 +340,6 @@ namespace System {
                                }
                        } else {
                                path = baseEl.path;
-#if !NET_4_0
-                               if (relativeEl.query != null) {
-                                       var pathEnd = path.LastIndexOf ('/');
-                                       path = (pathEnd > 0)? path.Substring (0, pathEnd+1) : "";
-                               }
-#endif
                        }
 
                        if ((path.Length == 0 || path [0] != '/') && baseEl.delimiter == SchemeDelimiter)
@@ -955,10 +947,8 @@ namespace System {
                //
                public Uri MakeRelativeUri (Uri uri)
                {
-#if NET_4_0
                        if (uri == null)
                                throw new ArgumentNullException ("uri");
-#endif
                        if (Host != uri.Host || Scheme != uri.Scheme)
                                return uri;
 
@@ -1727,7 +1717,7 @@ namespace System {
                private UriParser Parser {
                        get {
                                if (parser == null) {
-                                       parser = UriParser.GetParser (Scheme);
+                                       parser = UriParser.GetParser (scheme);
                                        // no specific parser ? then use a default one
                                        if (parser == null)
                                                parser = new DefaultUriParser ("*");
@@ -1739,15 +1729,16 @@ namespace System {
 
                public string GetComponents (UriComponents components, UriFormat format)
                {
+                       if ((components & UriComponents.SerializationInfoString) == 0)
+                               EnsureAbsoluteUri ();
+
                        return Parser.GetComponents (this, components, format);
                }
 
                public bool IsBaseOf (Uri uri)
                {
-#if NET_4_0
                        if (uri == null)
                                throw new ArgumentNullException ("uri");
-#endif
                        return Parser.IsBaseOf (this, uri);
                }
 
@@ -1771,6 +1762,10 @@ namespace System {
 
                        if ((uri1 == null) && (uri2 == null))
                                return 0;
+                       if (uri1 == null)
+                               return -1;
+                       if (uri2 == null)
+                               return 1;
 
                        string s1 = uri1.GetComponents (partsToCompare, compareFormat);
                        string s2 = uri2.GetComponents (partsToCompare, compareFormat);
@@ -1795,18 +1790,6 @@ namespace System {
                                return false;
                        }
 
-#if !NET_4_5
-                       switch (b) {
-                       case '!':
-                       case '\'':
-                       case '(':
-                       case ')':
-                       case '*':
-                       case '-':
-                       case '.':
-                               return false;
-                       }
-#endif
 
                        return true;
                }
@@ -1860,11 +1843,9 @@ namespace System {
                        case '_':
                        case '~':
                                return false;
-#if NET_4_5
                        case '[':
                        case ']':
                                return false;
-#endif
                        }
 
                        return true;
@@ -1952,10 +1933,8 @@ namespace System {
                        result = null;
                        if ((baseUri == null) || !baseUri.IsAbsoluteUri)
                                return false;
-#if NET_4_0
                        if (relativeUri == null)
                                return false;
-#endif
                        try {
                                // FIXME: this should call UriParser.Resolve
                                result = new Uri (baseUri, relativeUri.OriginalString);