Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
improve port parsing to be more resilient against trailing characters (
Browse files Browse the repository at this point in the history
…#31232) (#31327)

improve port parsing to be more resilient against trailing characters
  • Loading branch information
wfurt authored Aug 9, 2018
1 parent f602b21 commit d6f8efc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,18 @@ private static Uri GetUriFromString(string value)
else
{
host = value.Substring(0, separatorIndex);
if (!UInt16.TryParse(value.AsSpan(separatorIndex + 1), out port))
int endIndex = separatorIndex + 1;
// Strip any trailing characters after port number.
while (endIndex < value.Length)
{
if (!char.IsDigit(value[endIndex]))
{
break;
}
endIndex += 1;
}

if (!ushort.TryParse(value.AsSpan(separatorIndex + 1, endIndex - separatorIndex - 1), out port))
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public void HttpProxy_EnvironmentProxy_Loaded()
[InlineData("domain\\foo:[email protected]", "1.1.1.1", "80", "foo", "bar")]
[InlineData("domain%5Cfoo:[email protected]", "1.1.1.1", "80", "foo", "bar")]
[InlineData("HTTP://ABC.COM/", "abc.com", "80", null, null)]
[InlineData("http://10.30.62.64:7890/", "10.30.62.64", "7890", null, null)]
[InlineData("http://1.2.3.4:8888/foo", "1.2.3.4", "8888", null, null)]
public void HttpProxy_Uri_Parsing(string _input, string _host, string _port, string _user , string _password)
{
RemoteInvoke((input, host, port, user, password) =>
Expand Down

0 comments on commit d6f8efc

Please sign in to comment.