mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +00:00
fix: Fixed bug in IcdUriBuilder where Query property behaved differently to UriBuilder
This commit is contained in:
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Fixed bug in IcdUriBuilder where Query property behaved differently to UriBuilder
|
||||||
|
|
||||||
## [9.5.0] - 2019-06-10
|
## [9.5.0] - 2019-06-10
|
||||||
### Added
|
### Added
|
||||||
- Added Shim to read a list from xml with no root element
|
- Added Shim to read a list from xml with no root element
|
||||||
|
|||||||
@@ -37,10 +37,11 @@ namespace ICD.Common.Utils.Tests
|
|||||||
Assert.AreEqual(port, new IcdUriBuilder {Port = port}.Port);
|
Assert.AreEqual(port, new IcdUriBuilder {Port = port}.Port);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase("test")]
|
[TestCase("?test", "test")]
|
||||||
public void QueryTest(string query)
|
[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")]
|
[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", 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,
|
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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ namespace ICD.Common.Utils
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class IcdUriBuilder
|
public sealed class IcdUriBuilder
|
||||||
{
|
{
|
||||||
|
private string m_Query;
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -43,7 +45,7 @@ namespace ICD.Common.Utils
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets any query information included in the URI.
|
/// Gets or sets any query information included in the URI.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Query { get; set; }
|
public string Query { get { return m_Query == null ? null : "?" + m_Query; } set { m_Query = value; } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the scheme name of the URI.
|
/// Gets or sets the scheme name of the URI.
|
||||||
@@ -96,7 +98,7 @@ namespace ICD.Common.Utils
|
|||||||
Password = uri.GetPassword();
|
Password = uri.GetPassword();
|
||||||
Path = uri.AbsolutePath;
|
Path = uri.AbsolutePath;
|
||||||
Port = (ushort)uri.Port;
|
Port = (ushort)uri.Port;
|
||||||
Query = uri.Query;
|
Query = uri.Query == null ? null : uri.Query.TrimStart('?');
|
||||||
Scheme = uri.Scheme;
|
Scheme = uri.Scheme;
|
||||||
UserName = uri.GetUserName();
|
UserName = uri.GetUserName();
|
||||||
}
|
}
|
||||||
@@ -149,10 +151,7 @@ namespace ICD.Common.Utils
|
|||||||
|
|
||||||
// Query
|
// Query
|
||||||
if (!string.IsNullOrEmpty(Query))
|
if (!string.IsNullOrEmpty(Query))
|
||||||
{
|
|
||||||
builder.Append('?');
|
|
||||||
builder.Append(Query);
|
builder.Append(Query);
|
||||||
}
|
|
||||||
|
|
||||||
// Fragment
|
// Fragment
|
||||||
if (!string.IsNullOrEmpty(Fragment))
|
if (!string.IsNullOrEmpty(Fragment))
|
||||||
|
|||||||
Reference in New Issue
Block a user