mirror of
https://github.com/Sonarr/Sonarr.git
synced 2025-02-14 12:20:55 +02:00
Fixed: Cleaning paths for top level root folders
This commit is contained in:
parent
a6735e7a3f
commit
a001216957
@ -393,5 +393,26 @@ namespace NzbDrone.Common.Test
|
|||||||
PosixOnly();
|
PosixOnly();
|
||||||
path.AsOsAgnostic().IsPathValid(PathValidationType.CurrentOs).Should().BeFalse();
|
path.AsOsAgnostic().IsPathValid(PathValidationType.CurrentOs).Should().BeFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestCase(@"C:\", @"C:\")]
|
||||||
|
[TestCase(@"C:\\", @"C:\")]
|
||||||
|
[TestCase(@"C:\Test", @"C:\Test")]
|
||||||
|
[TestCase(@"C:\Test\", @"C:\Test")]
|
||||||
|
[TestCase(@"\\server\share", @"\\server\share")]
|
||||||
|
[TestCase(@"\\server\share\", @"\\server\share")]
|
||||||
|
public void windows_path_should_return_clean_path(string path, string cleanPath)
|
||||||
|
{
|
||||||
|
path.GetCleanPath().Should().Be(cleanPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase("/", "/")]
|
||||||
|
[TestCase("//", "/")]
|
||||||
|
[TestCase("/test", "/test")]
|
||||||
|
[TestCase("/test/", "/test")]
|
||||||
|
[TestCase("/test//", "/test")]
|
||||||
|
public void unix_path_should_return_clean_path(string path, string cleanPath)
|
||||||
|
{
|
||||||
|
path.GetCleanPath().Should().Be(cleanPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,9 +104,19 @@ namespace NzbDrone.Common.Disk
|
|||||||
switch (kind)
|
switch (kind)
|
||||||
{
|
{
|
||||||
case OsPathKind.Windows when !path.EndsWith(":\\"):
|
case OsPathKind.Windows when !path.EndsWith(":\\"):
|
||||||
return path.TrimEnd('\\');
|
while (!path.EndsWith(":\\") && path.EndsWith('\\'))
|
||||||
|
{
|
||||||
|
path = path[..^1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
case OsPathKind.Unix when path != "/":
|
case OsPathKind.Unix when path != "/":
|
||||||
return path.TrimEnd('/');
|
while (path != "/" && path.EndsWith('/'))
|
||||||
|
{
|
||||||
|
path = path[..^1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
|
@ -25,8 +25,6 @@ namespace NzbDrone.Common.Extensions
|
|||||||
private static readonly string UPDATE_CLIENT_FOLDER_NAME = "Sonarr.Update" + Path.DirectorySeparatorChar;
|
private static readonly string UPDATE_CLIENT_FOLDER_NAME = "Sonarr.Update" + Path.DirectorySeparatorChar;
|
||||||
private static readonly string UPDATE_LOG_FOLDER_NAME = "UpdateLogs" + Path.DirectorySeparatorChar;
|
private static readonly string UPDATE_LOG_FOLDER_NAME = "UpdateLogs" + Path.DirectorySeparatorChar;
|
||||||
|
|
||||||
private static readonly Regex PARENT_PATH_END_SLASH_REGEX = new Regex(@"(?<!:)\\$", RegexOptions.Compiled);
|
|
||||||
|
|
||||||
public static string CleanFilePath(this string path)
|
public static string CleanFilePath(this string path)
|
||||||
{
|
{
|
||||||
if (path.IsNotNullOrWhiteSpace())
|
if (path.IsNotNullOrWhiteSpace())
|
||||||
@ -113,11 +111,9 @@ namespace NzbDrone.Common.Extensions
|
|||||||
|
|
||||||
public static string GetCleanPath(this string path)
|
public static string GetCleanPath(this string path)
|
||||||
{
|
{
|
||||||
var cleanPath = OsInfo.IsWindows
|
var osPath = new OsPath(path);
|
||||||
? PARENT_PATH_END_SLASH_REGEX.Replace(path, "")
|
|
||||||
: path.TrimEnd(Path.DirectorySeparatorChar);
|
|
||||||
|
|
||||||
return cleanPath;
|
return osPath == OsPath.Null ? null : osPath.PathWithoutTrailingSlash;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsParentPath(this string parentPath, string childPath)
|
public static bool IsParentPath(this string parentPath, string childPath)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user