mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-17 05:35:07 +00:00
fix: IcdUriBuilder constructors behave closer to UriBuilder, Host defaults to "localhost"
This commit is contained in:
@@ -63,14 +63,15 @@ namespace ICD.Common.Utils.Tests
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
[TestCase("http:///", null, null, null, null, (ushort)0, null, null, null)]
|
[TestCase("/", null, null, null, null, (ushort)0, null, null, null)]
|
||||||
[TestCase("http://localhost:80/", null, "localhost", null, null, (ushort)80, null, null, null)]
|
[TestCase("http:///", null, null, null, null, (ushort)0, null, "http", null)]
|
||||||
[TestCase("http://username@localhost/", null, "localhost", null, null, (ushort)0, null, null, "username")]
|
[TestCase("http://localhost:80/", null, "localhost", null, null, (ushort)80, null, "http", null)]
|
||||||
[TestCase("http://localhost/", null, "localhost", "password", null, (ushort)0, null, null, null)]
|
[TestCase("http://username@localhost/", null, "localhost", null, null, (ushort)0, null, "http", "username")]
|
||||||
|
[TestCase("http://localhost/", null, "localhost", "password", null, (ushort)0, null, "http", null)]
|
||||||
[TestCase("https://localhost/", null, "localhost", null, null, (ushort)0, null, "https", null)]
|
[TestCase("https://localhost/", null, "localhost", null, null, (ushort)0, null, "https", null)]
|
||||||
[TestCase("http://localhost/test", null, "localhost", null, "test", (ushort)0, null, null, null)]
|
[TestCase("http://localhost/test", null, "localhost", null, "test", (ushort)0, null, "http", null)]
|
||||||
[TestCase("http://localhost/test", null, "localhost", null, "/test", (ushort)0, null, null, null)]
|
[TestCase("http://localhost/test", null, "localhost", null, "/test", (ushort)0, null, "http", null)]
|
||||||
[TestCase("http://localhost//test", null, "localhost", null, "//test", (ushort)0, null, null, null)]
|
[TestCase("http://localhost//test", null, "localhost", null, "//test", (ushort)0, null, "http", null)]
|
||||||
public void ToStringTest(string expected, string fragment, string address, string password, string path, ushort port,
|
public void ToStringTest(string expected, string fragment, string address, string password, string path, ushort port,
|
||||||
string query, string scheme, string userName)
|
string query, string scheme, string userName)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -107,20 +107,20 @@ namespace ICD.Common.Utils
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
// URI = scheme:[//authority]path[?query][#fragment]
|
// URI = [scheme://][authority]path[?query][#fragment]
|
||||||
// authority = [userinfo@]host[:port]
|
// authority = [userinfo@]host[:port]
|
||||||
// userinfo = username[:password]
|
// userinfo = username[:password]
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
// Scheme
|
// Scheme
|
||||||
string scheme = string.IsNullOrEmpty(Scheme) ? Uri.UriSchemeHttp : Scheme;
|
if (!string.IsNullOrEmpty(Scheme))
|
||||||
builder.Append(scheme);
|
{
|
||||||
builder.Append(':');
|
builder.Append(Scheme);
|
||||||
|
builder.Append("://");
|
||||||
|
}
|
||||||
|
|
||||||
// Authority
|
// Authority
|
||||||
builder.Append("//");
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(UserName))
|
if (!string.IsNullOrEmpty(UserName))
|
||||||
{
|
{
|
||||||
builder.Append(UserName);
|
builder.Append(UserName);
|
||||||
|
|||||||
Reference in New Issue
Block a user