Fix #2363 in Uri.CheckHostName().
authorYves Bastide <stid@acm.org>
Wed, 20 Jun 2012 01:02:19 +0000 (03:02 +0200)
committerMartin Baulig <martin.baulig@googlemail.com>
Wed, 20 Jun 2012 01:05:55 +0000 (03:05 +0200)
FIXME: We still violate RFC 2181 by not checking the total length of the
hostname (maximum 255 bytes), but .NET doesn't check it either.

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

index 0978cafb21bde30783ed892b70cff688441a647b..40ff6eafb09d5cd00f1562e8d2b57115326a002e 100644 (file)
@@ -773,6 +773,7 @@ namespace System {
                                        if (i + 1 < len && name [i + 1] == '.')
                                                return false;
                                        count = 0;
+                                       continue;
                                } else if (!Char.IsLetterOrDigit (c) && c != '-' && c != '_') {
                                        return false;
                                }
index b31f15b234747a9b356ee997410431b2c4f80f4f..4667dff48c65dcf978987d360e8d6bac47c36cac 100644 (file)
@@ -624,6 +624,19 @@ namespace MonoTests.System
                        {
                        }
                }
+
+               [Test]
+               public void DomainLabelLength ()
+               {
+                       UriHostNameType type = Uri.CheckHostName ("3.141592653589793238462643383279502884197169399375105820974944592.com");
+                       Assert.AreEqual (UriHostNameType.Dns, type, "DomainLabelLength#1");
+                       type = Uri.CheckHostName ("3141592653589793238462643383279502884197169399375105820974944592.com");
+                       Assert.AreEqual (UriHostNameType.Unknown, type, "DomainLabelLength#2");
+                       type = Uri.CheckHostName ("3.1415926535897932384626433832795028841971693993751058209749445923.com");
+                       Assert.AreEqual (UriHostNameType.Unknown, type, "DomainLabelLength#2");
+                       type = Uri.CheckHostName ("3.141592653589793238462643383279502884197169399375105820974944592._om");
+                       Assert.AreEqual (UriHostNameType.Unknown, type, "DomainLabelLength#3");
+               }
        }
 }