From 33b1d29781cd5e5f99c806c52591c3060e8e21a3 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Wed, 1 May 2019 17:05:22 -0400 Subject: [PATCH] fix: IcdUriBuilder constructors behave closer to UriBuilder, Host defaults to "localhost" --- ICD.Common.Utils.Tests/IcdUriBuilderTest.cs | 15 ++++++++------- ICD.Common.Utils/IcdUriBuilder.cs | 12 ++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/ICD.Common.Utils.Tests/IcdUriBuilderTest.cs b/ICD.Common.Utils.Tests/IcdUriBuilderTest.cs index 3baebfa..f407304 100644 --- a/ICD.Common.Utils.Tests/IcdUriBuilderTest.cs +++ b/ICD.Common.Utils.Tests/IcdUriBuilderTest.cs @@ -63,14 +63,15 @@ namespace ICD.Common.Utils.Tests #endregion - [TestCase("http:///", null, null, null, null, (ushort)0, null, null, null)] - [TestCase("http://localhost:80/", null, "localhost", null, null, (ushort)80, null, null, null)] - [TestCase("http://username@localhost/", null, "localhost", null, null, (ushort)0, null, null, "username")] - [TestCase("http://localhost/", null, "localhost", "password", null, (ushort)0, null, null, null)] + [TestCase("/", null, null, null, null, (ushort)0, null, null, null)] + [TestCase("http:///", null, null, null, null, (ushort)0, null, "http", null)] + [TestCase("http://localhost:80/", null, "localhost", null, null, (ushort)80, null, "http", 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("http://localhost/test", null, "localhost", null, "test", (ushort)0, null, null, 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, 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, "http", 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, string query, string scheme, string userName) { diff --git a/ICD.Common.Utils/IcdUriBuilder.cs b/ICD.Common.Utils/IcdUriBuilder.cs index 15d482f..40d2a19 100644 --- a/ICD.Common.Utils/IcdUriBuilder.cs +++ b/ICD.Common.Utils/IcdUriBuilder.cs @@ -107,20 +107,20 @@ namespace ICD.Common.Utils /// public override string ToString() { - // URI = scheme:[//authority]path[?query][#fragment] + // URI = [scheme://][authority]path[?query][#fragment] // authority = [userinfo@]host[:port] // userinfo = username[:password] StringBuilder builder = new StringBuilder(); // Scheme - string scheme = string.IsNullOrEmpty(Scheme) ? Uri.UriSchemeHttp : Scheme; - builder.Append(scheme); - builder.Append(':'); + if (!string.IsNullOrEmpty(Scheme)) + { + builder.Append(Scheme); + builder.Append("://"); + } // Authority - builder.Append("//"); - if (!string.IsNullOrEmpty(UserName)) { builder.Append(UserName);