Skip to content

Commit 184ca11

Browse files
committed
Fix parsing of *:0 in ParseTcpIpEndPoint.
1 parent 73373a1 commit 184ca11

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcTcpSocketEndPoint.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,26 @@ private static void ParseTcpIpEndPoint(string endPoint, out string host, out int
5050
port = -1;
5151

5252
bool usesWildcardHost = false;
53-
string uriToParse;
53+
string uriToParse= "";
5454

55-
// Host can contain wildcard (*) that is a reserved charachter in URI's.
56-
// Replace with dummy localhost representation just for parsing purpose.
57-
if (endPoint.StartsWith("*", StringComparison.Ordinal))
55+
if (endPoint.Contains("://"))
5856
{
59-
usesWildcardHost = true;
60-
uriToParse = "localhost" + endPoint.Substring(1);
61-
}
62-
else if (endPoint.IndexOf("//*", StringComparison.Ordinal) != -1)
63-
{
64-
usesWildcardHost = true;
65-
uriToParse = endPoint.Replace("//*", "//localhost");
66-
}
67-
else
68-
{
69-
uriToParse = endPoint;
57+
// Host can contain wildcard (*) that is a reserved charachter in URI's.
58+
// Replace with dummy localhost representation just for parsing purpose.
59+
if (endPoint.IndexOf("//*", StringComparison.Ordinal) != -1)
60+
{
61+
usesWildcardHost = true;
62+
uriToParse = endPoint.Replace("//*", "//localhost");
63+
}
64+
else
65+
{
66+
uriToParse = endPoint;
67+
}
7068
}
7169

7270
try
7371
{
74-
if (Uri.TryCreate(uriToParse, UriKind.RelativeOrAbsolute, out Uri uri))
72+
if (!string.IsNullOrEmpty(uriToParse) && Uri.TryCreate(uriToParse, UriKind.RelativeOrAbsolute, out Uri uri))
7573
{
7674
if (string.Compare(uri.Scheme, Uri.UriSchemeNetTcp, StringComparison.OrdinalIgnoreCase) != 0 &&
7775
string.Compare(uri.Scheme, "tcp", StringComparison.OrdinalIgnoreCase) != 0)

0 commit comments

Comments
 (0)