Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parsing of zero port for unknown Uri scheme #40986

Merged
merged 3 commits into from
Aug 18, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions src/libraries/System.Private.Uri/tests/FunctionalTests/UriTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -819,23 +819,22 @@ public static void FilePathHandlesNonAscii(string uriString, string toString, st
Assert.Equal(localPath, uri2.LocalPath);
}

[Fact]
public static void ZeroPortIsParsedForBothKnownAndUnknownSchemes()
public static IEnumerable<object[]> ZeroPortIsParsedForBothKnownAndUnknownSchemes_TestData()
{
Uri.TryCreate("http://example.com:0", UriKind.Absolute, out var uri);
Assert.Equal(0, uri.Port);
Assert.False(uri.IsDefaultPort);
Assert.Equal("http://example.com:0/", uri.ToString());

Uri.TryCreate("rtsp://example.com", UriKind.Absolute, out uri);
Assert.Equal(-1, uri.Port);
Assert.True(uri.IsDefaultPort);
Assert.Equal("rtsp://example.com/", uri.ToString());
yield return new object[] { "http://example.com:0", 0, false, "http://example.com:0/" };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is toString same as the uriString except the trailing slash? Do we need the extra parameter?

yield return new object[] { "http://example.com", 80, true, "http://example.com/" };
yield return new object[] { "rtsp://example.com:0", 0, false, "rtsp://example.com:0/" };
yield return new object[] { "rtsp://example.com", -1, true, "rtsp://example.com/" };
}

Uri.TryCreate("rtsp://example.com:0", UriKind.Absolute, out uri);
Assert.Equal(0, uri.Port);
Assert.False(uri.IsDefaultPort);
Assert.Equal("rtsp://example.com:0/", uri.ToString());
[Theory]
[MemberData(nameof(ZeroPortIsParsedForBothKnownAndUnknownSchemes_TestData))]
public static void ZeroPortIsParsedForBothKnownAndUnknownSchemes(string uriString, int port, bool isDefaultPort, string toString)
{
Uri.TryCreate(uriString, UriKind.Absolute, out var uri);
Assert.Equal(port, uri.Port);
Assert.Equal(isDefaultPort, uri.IsDefaultPort);
Assert.Equal(toString, uri.ToString());
}
}
}