Skip to content

Commit

Permalink
Fix Uri when a colon ':' is not followed by a port number
Browse files Browse the repository at this point in the history
* System/Uri.cs: Fix parsing the port/host when a ':' is present without
a port number on non-file:// URI

* Test/System/UriTest2.cs: Add test cases where an URI contains a ':'
but is not followed by a port number
  • Loading branch information
Sebastien Pouliot committed Sep 17, 2010
1 parent f75017f commit b3619d3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 7 additions & 3 deletions mcs/class/System/System/Uri.cs
Expand Up @@ -1528,10 +1528,14 @@ private string ParseNoExceptions (UriKind kind, string uriString)
port = GetDefaultPort (scheme);
}
}
} else {
if (port == -1) {
} else if (!IsFile) {
// if no port is specified by a colon ':' is present then we must ignore it
// since it would be part of the host name and, as such, would be invalid
if (pos == endpos - 1)
endpos--;

if (port == -1)
port = GetDefaultPort (scheme);
}
}

// 4 authority
Expand Down
16 changes: 16 additions & 0 deletions mcs/class/System/Test/System/UriTest2.cs
Expand Up @@ -879,5 +879,21 @@ public void PathReduction_2e ()
Assert.AreEqual ("/", uri.Segments [0], "Segments [0]");
Assert.AreEqual ("file", uri.Segments [1], "Segments [1]");
}

[Test]
public void ColonButNoPort ()
{
Uri uri = new Uri ("http://host:");
Assert.AreEqual ("http", uri.Scheme, "1.Scheme");
Assert.AreEqual ("host", uri.Host, "1.Host");
Assert.AreEqual (80, uri.Port, "1.Port");
Assert.IsTrue (uri.IsDefaultPort, "1.IsDefaultPort");

uri = new Uri ("ftp://host:/dir/file");
Assert.AreEqual ("ftp", uri.Scheme, "2.Scheme");
Assert.AreEqual ("host", uri.Host, "2.Host");
Assert.AreEqual (21, uri.Port, "2.Port");
Assert.IsTrue (uri.IsDefaultPort, "2.IsDefaultPort");
}
}
}

0 comments on commit b3619d3

Please sign in to comment.