mirror of
https://github.com/Prowlarr/Prowlarr
synced 2025-12-15 21:14:32 +01:00
Fixed: Correctly handle relative redirects with dot segments
This commit is contained in:
parent
9860183433
commit
70685de5d2
3 changed files with 52 additions and 0 deletions
|
|
@ -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")]
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ public string RedirectUrl
|
|||
get
|
||||
{
|
||||
var newUrl = Headers["Location"];
|
||||
|
||||
if (newUrl == null)
|
||||
{
|
||||
newUrl = Headers["Refresh"];
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue