Skip to content

IPAddress.TryParse() incorrectly parses "::2:3:4:5:6:7:8" #29930

@vyrp

Description

@vyrp

The method System.Net.IPAddress.TryParse() incorrectly parses "::2:3:4:5:6:7:8".

According to RFC 4291, "The use of "::" indicates one or more groups of 16 bits of zeros" (emphasis mine). Therefore, I would expect "::2:3:4:5:6:7:8" to be valid and the leading "::" to represent a zero.

For example, for the following code:

Console.WriteLine(IPAddress.TryParse("::2:3:4:5:6:7:8", out var addr) ? addr.ToString() : "error");

Actual output:

::

Expected output:

0:2:3:4:5:6:7:8

I find the actual output very strange. In .NET Framework, the result was false, which I don't think is correct, but at least wass less surprising.

Environment:

.NET Core SDK (reflecting any global.json):
 Version:   2.2.107
 Commit:    2212cac826

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.107\

Host (useful for support):
  Version: 2.2.5
  Commit:  0a3c9209c0

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions