From e8acb42bb9072500d0d88ac7e7da407a94216105 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Fri, 21 Jun 2019 21:32:46 -0400 Subject: [PATCH] fix: Fixed bug in IcdUriBuilder where Query property behaved differently to UriBuilder --- CHANGELOG.md | 3 +++ ICD.Common.Utils.Tests/IcdUriBuilderTest.cs | 9 ++++++--- ICD.Common.Utils/IcdUriBuilder.cs | 9 ++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cbee3e..b77f9fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed + - Fixed bug in IcdUriBuilder where Query property behaved differently to UriBuilder + ## [9.5.0] - 2019-06-10 ### Added - Added Shim to read a list from xml with no root element diff --git a/ICD.Common.Utils.Tests/IcdUriBuilderTest.cs b/ICD.Common.Utils.Tests/IcdUriBuilderTest.cs index f407304..4fe1b0c 100644 --- a/ICD.Common.Utils.Tests/IcdUriBuilderTest.cs +++ b/ICD.Common.Utils.Tests/IcdUriBuilderTest.cs @@ -37,10 +37,11 @@ namespace ICD.Common.Utils.Tests Assert.AreEqual(port, new IcdUriBuilder {Port = port}.Port); } - [TestCase("test")] - public void QueryTest(string query) + [TestCase("?test", "test")] + [TestCase("??test", "?test")] + public void QueryTest(string expected, string query) { - Assert.AreEqual(query, new IcdUriBuilder {Query = query}.Query); + Assert.AreEqual(expected, new IcdUriBuilder {Query = query}.Query); } [TestCase("test")] @@ -72,6 +73,8 @@ namespace ICD.Common.Utils.Tests [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)] + [TestCase("http://localhost/test?a=b", null, "localhost", null, "/test", (ushort)0, "a=b", "http", null)] + [TestCase("http://localhost/test??a=b", null, "localhost", null, "/test", (ushort)0, "?a=b", "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 40d2a19..4a0a212 100644 --- a/ICD.Common.Utils/IcdUriBuilder.cs +++ b/ICD.Common.Utils/IcdUriBuilder.cs @@ -13,6 +13,8 @@ namespace ICD.Common.Utils /// public sealed class IcdUriBuilder { + private string m_Query; + #region Properties /// @@ -43,7 +45,7 @@ namespace ICD.Common.Utils /// /// Gets or sets any query information included in the URI. /// - public string Query { get; set; } + public string Query { get { return m_Query == null ? null : "?" + m_Query; } set { m_Query = value; } } /// /// Gets or sets the scheme name of the URI. @@ -96,7 +98,7 @@ namespace ICD.Common.Utils Password = uri.GetPassword(); Path = uri.AbsolutePath; Port = (ushort)uri.Port; - Query = uri.Query; + Query = uri.Query == null ? null : uri.Query.TrimStart('?'); Scheme = uri.Scheme; UserName = uri.GetUserName(); } @@ -149,10 +151,7 @@ namespace ICD.Common.Utils // Query if (!string.IsNullOrEmpty(Query)) - { - builder.Append('?'); builder.Append(Query); - } // Fragment if (!string.IsNullOrEmpty(Fragment))