fix: Fixed bug in IcdUriBuilder where Query property behaved differently to UriBuilder

This commit is contained in:
Chris Cameron
2019-06-21 21:32:46 -04:00
parent d3d812265e
commit e8acb42bb9
3 changed files with 13 additions and 8 deletions

View File

@@ -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

View File

@@ -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)
{

View File

@@ -13,6 +13,8 @@ namespace ICD.Common.Utils
/// </summary>
public sealed class IcdUriBuilder
{
private string m_Query;
#region Properties
/// <summary>
@@ -43,7 +45,7 @@ namespace ICD.Common.Utils
/// <summary>
/// Gets or sets any query information included in the URI.
/// </summary>
public string Query { get; set; }
public string Query { get { return m_Query == null ? null : "?" + m_Query; } set { m_Query = value; } }
/// <summary>
/// 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))