mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Cleanup HttpUri.PathCombine
This commit is contained in:
parent
edea488dbe
commit
502298aab9
29
src/NzbDrone.Common.Test/Http/HttpUriFixture.cs
Normal file
29
src/NzbDrone.Common.Test/Http/HttpUriFixture.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common.Http;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
|
namespace NzbDrone.Common.Test.Http
|
||||||
|
{
|
||||||
|
public class HttpUriFixture : TestBase
|
||||||
|
{
|
||||||
|
private HttpUri GivenHttpUri(string basePath)
|
||||||
|
{
|
||||||
|
return new HttpUri("http", "localhost", 8989, basePath, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase("", "", "")]
|
||||||
|
[TestCase("base", "", "/base")]
|
||||||
|
[TestCase("/base", "", "/base")]
|
||||||
|
[TestCase("", "relative", "/relative")]
|
||||||
|
[TestCase("", "/relative", "/relative")]
|
||||||
|
[TestCase("base", "relative", "/base/relative")]
|
||||||
|
[TestCase("base", "/relative", "/base/relative")]
|
||||||
|
[TestCase("/base", "relative", "/base/relative")]
|
||||||
|
[TestCase("/base", "/relative", "/base/relative")]
|
||||||
|
public void should_combine_base_path_and_relative_path(string basePath, string relativePath, string expected)
|
||||||
|
{
|
||||||
|
GivenHttpUri(basePath).CombinePath(relativePath).Path.Should().Be(expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -83,6 +83,7 @@
|
|||||||
<Compile Include="Http\HttpClientFixture.cs" />
|
<Compile Include="Http\HttpClientFixture.cs" />
|
||||||
<Compile Include="Http\HttpRequestBuilderFixture.cs" />
|
<Compile Include="Http\HttpRequestBuilderFixture.cs" />
|
||||||
<Compile Include="Http\HttpRequestFixture.cs" />
|
<Compile Include="Http\HttpRequestFixture.cs" />
|
||||||
|
<Compile Include="Http\HttpUriFixture.cs" />
|
||||||
<Compile Include="InstrumentationTests\CleanseLogMessageFixture.cs" />
|
<Compile Include="InstrumentationTests\CleanseLogMessageFixture.cs" />
|
||||||
<Compile Include="LevenshteinDistanceFixture.cs" />
|
<Compile Include="LevenshteinDistanceFixture.cs" />
|
||||||
<Compile Include="OsPathFixture.cs" />
|
<Compile Include="OsPathFixture.cs" />
|
||||||
|
@ -144,23 +144,12 @@ private static string CombinePath(string basePath, string relativePath)
|
|||||||
return basePath;
|
return basePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
var newPath = "/" + relativePath.TrimStart('/');
|
if (basePath.IsNullOrWhiteSpace())
|
||||||
|
|
||||||
if (basePath != null && !relativePath.StartsWith("/"))
|
|
||||||
{
|
{
|
||||||
var baseSlashIndex = basePath.LastIndexOf('/');
|
return "/" + relativePath.TrimStart('/');
|
||||||
|
|
||||||
if (baseSlashIndex == basePath.Length - 1)
|
|
||||||
{
|
|
||||||
newPath = basePath.TrimEnd('/') + newPath;
|
|
||||||
}
|
|
||||||
else if (baseSlashIndex != 0)
|
|
||||||
{
|
|
||||||
newPath = basePath.Substring(0, baseSlashIndex) + newPath;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newPath;
|
return basePath.TrimEnd("/") + "/" + relativePath.TrimStart('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpUri SetQuery(string query)
|
public HttpUri SetQuery(string query)
|
||||||
@ -199,7 +188,6 @@ public HttpUri AddQueryParams(IEnumerable<KeyValuePair<string, string>> queryPar
|
|||||||
return SetQuery(builder.ToString());
|
return SetQuery(builder.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
{
|
{
|
||||||
return _uri.GetHashCode();
|
return _uri.GetHashCode();
|
||||||
|
Loading…
Reference in New Issue
Block a user