Fixed: Allow leading/trailing spaces on non-Windows

Closes #6971
This commit is contained in:
Mark McDowall 2024-07-28 20:16:51 -07:00 committed by Mark McDowall
parent cc85a28ff7
commit 9127a91dfc
2 changed files with 22 additions and 9 deletions

View File

@ -380,8 +380,17 @@ namespace NzbDrone.Common.Test
[TestCase(@" C:\Test\TV\")]
[TestCase(@" C:\Test\TV")]
public void IsPathValid_should_be_false(string path)
public void IsPathValid_should_be_false_on_windows(string path)
{
WindowsOnly();
path.IsPathValid(PathValidationType.CurrentOs).Should().BeFalse();
}
[TestCase(@"")]
[TestCase(@"relative/path")]
public void IsPathValid_should_be_false_on_unix(string path)
{
PosixOnly();
path.AsOsAgnostic().IsPathValid(PathValidationType.CurrentOs).Should().BeFalse();
}
}

View File

@ -152,16 +152,20 @@ namespace NzbDrone.Common.Extensions
return false;
}
var directoryInfo = new DirectoryInfo(path);
while (directoryInfo != null)
// Only check for leading or trailing spaces for path when running on Windows.
if (OsInfo.IsWindows)
{
if (directoryInfo.Name.Trim() != directoryInfo.Name)
{
return false;
}
var directoryInfo = new DirectoryInfo(path);
directoryInfo = directoryInfo.Parent;
while (directoryInfo != null)
{
if (directoryInfo.Name.Trim() != directoryInfo.Name)
{
return false;
}
directoryInfo = directoryInfo.Parent;
}
}
if (validationType == PathValidationType.AnyOs)