Lower-case the host in Uri.TryCreate to match behavior of constructors
authorMartin Potter <martin.potter@logos.com>
Thu, 21 Aug 2014 13:43:52 +0000 (06:43 -0700)
committerMartin Potter <martin.potter@logos.com>
Thu, 21 Aug 2014 13:43:52 +0000 (06:43 -0700)
On Microsoft's implementation of the Uri class, the contructors and TryCreate method both lower-case the host. This commit fixes the issue where the constructors lower-cased the host but the TryCreate method did not.

mcs/class/System/System/Uri.cs
mcs/class/System/Test/System/UriTest3.cs

index e74ef5d2f09f8d13cddfbb8ddbb375ef0f3c5abd..5a6b930d40201ba539cdf7809e3bb523b38786a1 100644 (file)
@@ -235,6 +235,11 @@ namespace System {
                                        success = false;
                                        break;
                                }
+
+                               if (success && host.Length > 1 && host [0] != '[' && host [host.Length - 1] != ']') {
+                                       // host name present (but not an IPv6 address)
+                                       host = host.ToLower (CultureInfo.InvariantCulture);
+                               }
                        }
                }
 
@@ -1142,9 +1147,6 @@ namespace System {
                {
                        Parse (kind, source);
 
-                       if (userEscaped)
-                               return;
-
                        if (host.Length > 1 && host [0] != '[' && host [host.Length - 1] != ']') {
                                // host name present (but not an IPv6 address)
                                host = host.ToLower (CultureInfo.InvariantCulture);
index 8fe73931954eb6023ebd7176a3a88b0fb135c95c..db22913e3a760586a824230d855eed384a2d9dbf 100644 (file)
@@ -184,6 +184,12 @@ namespace MonoTests.System
 
                        Assert.IsTrue (Uri.TryCreate ("http://mono-project.com/☕", UriKind.Absolute, out uri), "highunicode-Absolute");
                        Assert.AreEqual("http://mono-project.com/%E2%98%95", uri.AbsoluteUri, "highunicode-Absolute-AbsoluteUri");
+
+                       string mixedCaseUri = "http://mOnO-proJECT.com";
+                       uri = new Uri (mixedCaseUri);
+                       Uri uri2;
+                       Assert.IsTrue (Uri.TryCreate (mixedCaseUri, UriKind.Absolute, out uri2), "mixedcasehost-absolute");
+                       Assert.AreEqual (uri.AbsoluteUri, uri2.AbsoluteUri, "mixedcasehost-absoluteuri-absoluteuri");
                }
 
                [Test] // TryCreate (String, UriKind, Uri)