Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
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
4 changes: 4 additions & 0 deletions src/Http/Http/src/BindingAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ public static BindingAddress Parse(string address)
host = address.Substring(schemeDelimiterEnd, portDelimiterStart - schemeDelimiterEnd);
port = portNumber;
}
else
{
throw new FormatException($"Invalid port: '{portString}, only numbers are allowed'");
}
}

if (!hasSpecifiedPort)
Expand Down
21 changes: 18 additions & 3 deletions src/Http/Http/test/BindingAddressTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ public void FromUriThrowsForUrlsWithoutHost(string url)
Assert.Throws<FormatException>(() => BindingAddress.Parse(url));
}

[Theory]
[InlineData("http://localhost:NOTAPORT")]
[InlineData("http://localhost:NOTAPORT/")]
[InlineData("http://localhost:NOTAPORT/random/url")]
[InlineData("https://localhost:NOTAPORT")]
[InlineData("https://localhost:NOTAPORT/")]
[InlineData("https://localhost:NOTAPORT/random/url")]
[InlineData("http://www.example.com:NOTAPORT")]
[InlineData("http://www.example.com:NOTAPORT/")]
[InlineData("http://www.example.com:NOTAPORT/foo?bar=baz")]
[InlineData("https://www.example.com:NOTAPORT")]
[InlineData("https://www.example.com:NOTAPORT/")]
[InlineData("https://www.example.com:NOTAPORT/foo?bar=baz")]
public void FromUriThrowsForUrlsWithInvalidPortNumbers(string url)
{
Assert.Throws<FormatException>(() => BindingAddress.Parse(url));
}

[ConditionalTheory]
[InlineData("http://unix:/")]
[InlineData("http://unix:/c")]
Expand All @@ -52,9 +70,6 @@ public void FromUriThrowsForUrlsWithWrongFilePathOnWindows(string url)
[InlineData("http://www.example.com:5000", "http", "www.example.com", 5000, "", null)]
[InlineData("https://www.example.com:5000", "https", "www.example.com", 5000, "", null)]
[InlineData("http://www.example.com:5000/", "http", "www.example.com", 5000, "", "http://www.example.com:5000")]
[InlineData("http://www.example.com:NOTAPORT", "http", "www.example.com:NOTAPORT", 80, "", "http://www.example.com:notaport:80")]
[InlineData("https://www.example.com:NOTAPORT", "https", "www.example.com:NOTAPORT", 443, "", "https://www.example.com:notaport:443")]
[InlineData("http://www.example.com:NOTAPORT/", "http", "www.example.com:NOTAPORT", 80, "", "http://www.example.com:notaport:80")]
[InlineData("http://foo:/tmp/kestrel-test.sock:5000/doesn't/matter", "http", "foo:", 80, "/tmp/kestrel-test.sock:5000/doesn't/matter", "http://foo::80/tmp/kestrel-test.sock:5000/doesn't/matter")]
[InlineData("http://unix:foo/tmp/kestrel-test.sock", "http", "unix:foo", 80, "/tmp/kestrel-test.sock", "http://unix:foo:80/tmp/kestrel-test.sock")]
[InlineData("http://unix:5000/tmp/kestrel-test.sock", "http", "unix", 5000, "/tmp/kestrel-test.sock", "http://unix:5000/tmp/kestrel-test.sock")]
Expand Down
Loading