diff --git a/src/NzbDrone.Common.Test/PathExtensionFixture.cs b/src/NzbDrone.Common.Test/PathExtensionFixture.cs index 21abab6e8..f0a42b0cd 100644 --- a/src/NzbDrone.Common.Test/PathExtensionFixture.cs +++ b/src/NzbDrone.Common.Test/PathExtensionFixture.cs @@ -379,8 +379,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(); } } diff --git a/src/NzbDrone.Common/Extensions/PathExtensions.cs b/src/NzbDrone.Common/Extensions/PathExtensions.cs index a97761592..0d8373a98 100644 --- a/src/NzbDrone.Common/Extensions/PathExtensions.cs +++ b/src/NzbDrone.Common/Extensions/PathExtensions.cs @@ -153,16 +153,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) + var directoryInfo = new DirectoryInfo(path); + + while (directoryInfo != null) { - return false; - } + if (directoryInfo.Name.Trim() != directoryInfo.Name) + { + return false; + } - directoryInfo = directoryInfo.Parent; + directoryInfo = directoryInfo.Parent; + } } if (validationType == PathValidationType.AnyOs)