[System] Fix parsing of URI schemes with digits
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Wed, 6 Aug 2014 12:52:42 +0000 (14:52 +0200)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Wed, 6 Aug 2014 12:53:01 +0000 (14:53 +0200)
Initializing an Uri previously throwed an exception when the URI scheme contained a digit (e.g. net.p2p).
The loop was missing a digit check, similar to https://github.com/mono/mono/blob/1f1dc988ad7b165603a1175bf0a92156c4372c43/mcs/class/System/System/Uri.cs#L767

mcs/class/System/System/UriParseComponents.cs
mcs/class/System/Test/System/UriTest.cs

index 47716481489c1fc1f9d7a0ac28f3936badd47a10..b7d4208ed2bf880fab7ded819212bf3a78e36492 100644 (file)
@@ -228,7 +228,7 @@ namespace System {
                        int index;
                        for (index = 1; index < part.Length; index++ ) {
                                char ch = part [index];
-                               if (ch != '.' && ch != '-' && ch != '+' && !IsAlpha (ch))
+                               if (ch != '.' && ch != '-' && ch != '+' && !IsAlpha (ch) && !Char.IsDigit (ch))
                                        break;
                                
                                sb.Append (ch);
index 512dc4b2719f3195dc72e7d99ee805d3545e1338..cb640ab44d8e3853ac84819727f1022874db825d 100644 (file)
@@ -1434,6 +1434,13 @@ namespace MonoTests.System
                        new Uri ("hey");
                }
 
+               [Test]
+               public void SchemeWithDigits ()
+               {
+                       Uri uri = new Uri ("net.p2p://foobar");
+                       Assert.AreEqual ("net.p2p", uri.Scheme);
+               }
+
                // on .NET 2.0 a port number is limited to UInt16.MaxValue
                [ExpectedException (typeof (UriFormatException))]
                [Test]