ServerAddress.FromUrl() should throw if Host is missing (#860)
This commit is contained in:
parent
6b25ee7343
commit
306084356e
|
|
@ -141,6 +141,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel
|
||||||
serverAddress.Host = url.Substring(schemeDelimiterEnd, pathDelimiterStart - schemeDelimiterEnd);
|
serverAddress.Host = url.Substring(schemeDelimiterEnd, pathDelimiterStart - schemeDelimiterEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(serverAddress.Host))
|
||||||
|
{
|
||||||
|
throw new FormatException($"Invalid URL: {url}");
|
||||||
|
}
|
||||||
|
|
||||||
// Path should not end with a / since it will be used as PathBase later
|
// Path should not end with a / since it will be used as PathBase later
|
||||||
if (url[url.Length - 1] == '/')
|
if (url[url.Length - 1] == '/')
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,29 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
[InlineData("")]
|
[InlineData("")]
|
||||||
[InlineData("5000")]
|
[InlineData("5000")]
|
||||||
[InlineData("//noscheme")]
|
[InlineData("//noscheme")]
|
||||||
public void FromUriThrowsForSchemelessUrls(string url)
|
public void FromUriThrowsForUrlsWithoutSchemeDelimiter(string url)
|
||||||
|
{
|
||||||
|
Assert.Throws<FormatException>(() => ServerAddress.FromUrl(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("://")]
|
||||||
|
[InlineData("://:5000")]
|
||||||
|
[InlineData("http://")]
|
||||||
|
[InlineData("http://:5000")]
|
||||||
|
[InlineData("http:///")]
|
||||||
|
[InlineData("http:///:5000")]
|
||||||
|
[InlineData("http:////")]
|
||||||
|
[InlineData("http:////:5000")]
|
||||||
|
public void FromUriThrowsForUrlsWithoutHost(string url)
|
||||||
{
|
{
|
||||||
Assert.Throws<FormatException>(() => ServerAddress.FromUrl(url));
|
Assert.Throws<FormatException>(() => ServerAddress.FromUrl(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("://emptyscheme", "", "emptyscheme", 0, "", "://emptyscheme:0")]
|
[InlineData("://emptyscheme", "", "emptyscheme", 0, "", "://emptyscheme:0")]
|
||||||
|
[InlineData("http://+", "http", "+", 80, "", "http://+:80")]
|
||||||
|
[InlineData("http://*", "http", "*", 80, "", "http://*:80")]
|
||||||
[InlineData("http://localhost", "http", "localhost", 80, "", "http://localhost:80")]
|
[InlineData("http://localhost", "http", "localhost", 80, "", "http://localhost:80")]
|
||||||
[InlineData("http://www.example.com", "http", "www.example.com", 80, "", "http://www.example.com:80")]
|
[InlineData("http://www.example.com", "http", "www.example.com", 80, "", "http://www.example.com:80")]
|
||||||
[InlineData("https://www.example.com", "https", "www.example.com", 443, "", "https://www.example.com:443")]
|
[InlineData("https://www.example.com", "https", "www.example.com", 443, "", "https://www.example.com:443")]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue