diff --git a/src/NzbDrone.Common.Test/Http/HttpUriFixture.cs b/src/NzbDrone.Common.Test/Http/HttpUriFixture.cs index d25d07bfe..18c5c20fb 100644 --- a/src/NzbDrone.Common.Test/Http/HttpUriFixture.cs +++ b/src/NzbDrone.Common.Test/Http/HttpUriFixture.cs @@ -53,6 +53,26 @@ public void should_combine_uri(string basePath, string relativePath, string expe newUri.FullUri.Should().Be(expected); } + [TestCase("", "./relative", "relative")] + [TestCase("/", "./relative", "/relative")] + [TestCase("/base", "./relative", "/relative")] + [TestCase("/base/sub", "./relative", "/base/relative")] + [TestCase("/base/sub/", "./relative", "/base/sub/relative")] + [TestCase("base/sub", "./relative", "base/relative")] + [TestCase("base/sub/", "./relative", "base/sub/relative")] + [TestCase("", "../relative", "relative")] + [TestCase("/", "../relative", "/relative")] + [TestCase("/base", "../relative", "/relative")] + [TestCase("/base/sub", "../relative", "/base/relative")] + [TestCase("/base/sub/", "../relative", "/base/sub/relative")] + [TestCase("base/sub", "../relative", "base/relative")] + [TestCase("base/sub/", "../relative", "base/sub/relative")] + public void should_combine_uri_with_dot_segment(string basePath, string relativePath, string expected) + { + var newUri = new HttpUri(basePath) + new HttpUri(relativePath); + newUri.FullUri.Should().Be(expected); + } + [TestCase("", "", "")] [TestCase("/", "", "/")] [TestCase("base", "", "base")] diff --git a/src/NzbDrone.Common/Http/HttpResponse.cs b/src/NzbDrone.Common/Http/HttpResponse.cs index 53459b5fc..a6c9f7f86 100644 --- a/src/NzbDrone.Common/Http/HttpResponse.cs +++ b/src/NzbDrone.Common/Http/HttpResponse.cs @@ -76,6 +76,7 @@ public string RedirectUrl get { var newUrl = Headers["Location"]; + if (newUrl == null) { newUrl = Headers["Refresh"]; diff --git a/src/NzbDrone.Common/Http/HttpUri.cs b/src/NzbDrone.Common/Http/HttpUri.cs index ecd4abf70..45d2b98b5 100644 --- a/src/NzbDrone.Common/Http/HttpUri.cs +++ b/src/NzbDrone.Common/Http/HttpUri.cs @@ -166,6 +166,37 @@ private static string CombineRelativePath(string basePath, string relativePath) return relativePath; } + if (relativePath.StartsWith("./")) + { + relativePath = relativePath.TrimStart('.').TrimStart('/'); + + var lastIndex = basePath.LastIndexOf("/"); + + if (lastIndex > 0) + { + basePath = basePath.Substring(0, lastIndex) + "/"; + } + } + + if (relativePath.StartsWith("../")) + { + relativePath = relativePath.TrimStart('.').TrimStart('/'); + + var lastIndex = basePath.LastIndexOf("/"); + + if (lastIndex > 0) + { + basePath = basePath.Substring(0, lastIndex) + "/"; + } + + var secondLastIndex = basePath.LastIndexOf("/"); + + if (lastIndex > 0) + { + basePath = basePath.Substring(0, secondLastIndex) + "/"; + } + } + var baseSlashIndex = basePath.LastIndexOf('/'); if (baseSlashIndex >= 0)