Skip to content

Commit

Permalink
Fixed: Revert "Validate that folders in paths don't start or end with…
Browse files Browse the repository at this point in the history
… a space"

This reverts commit 0d0575f.
  • Loading branch information
mynameisbogdan committed May 14, 2024
1 parent ff3dd3a commit 077b041
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 57 deletions.
28 changes: 1 addition & 27 deletions src/NzbDrone.Common.Test/PathExtensionFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Disk;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions;
using NzbDrone.Test.Common;
Expand Down Expand Up @@ -35,7 +34,7 @@ private IAppFolderInfo GetIAppDirectoryInfo()
[TestCase(@"\\Testserver\\Test\", @"\\Testserver\Test")]
[TestCase(@"\\Testserver\Test\file.ext", @"\\Testserver\Test\file.ext")]
[TestCase(@"\\Testserver\Test\file.ext\\", @"\\Testserver\Test\file.ext")]
[TestCase(@"\\Testserver\Test\file.ext ", @"\\Testserver\Test\file.ext")]
[TestCase(@"\\Testserver\Test\file.ext \\", @"\\Testserver\Test\file.ext")]
[TestCase(@"//CAPITAL//lower// ", @"\\CAPITAL\lower")]
public void Clean_Path_Windows(string dirty, string clean)
{
Expand Down Expand Up @@ -335,30 +334,5 @@ public void GetAncestorFolders_should_return_all_ancestors_in_path_Linux()
result[2].Should().Be(@"TV");
result[3].Should().Be(@"Series Title");
}

[TestCase(@"C:\Test\")]
[TestCase(@"C:\Test")]
[TestCase(@"C:\Test\TV\")]
[TestCase(@"C:\Test\TV")]
public void IsPathValid_should_be_true(string path)
{
path.AsOsAgnostic().IsPathValid(PathValidationType.CurrentOs).Should().BeTrue();
}

[TestCase(@"C:\Test \")]
[TestCase(@"C:\Test ")]
[TestCase(@"C:\ Test\")]
[TestCase(@"C:\ Test")]
[TestCase(@"C:\Test \TV")]
[TestCase(@"C:\ Test\TV")]
[TestCase(@"C:\Test \TV\")]
[TestCase(@"C:\ Test\TV\")]
[TestCase(@" C:\Test\TV\")]
[TestCase(@" C:\Test\TV")]

public void IsPathValid_should_be_false(string path)
{
path.AsOsAgnostic().IsPathValid(PathValidationType.CurrentOs).Should().BeFalse();
}
}
}
32 changes: 2 additions & 30 deletions src/NzbDrone.Common/Extensions/PathExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ public static class PathExtensions

public static string CleanFilePath(this string path)
{
if (path.IsNotNullOrWhiteSpace())
{
// Trim trailing spaces before checking if the path is valid so validation doesn't fail for something we can fix.
path = path.TrimEnd(' ');
}

Ensure.That(path, () => path).IsNotNullOrWhiteSpace();
Ensure.That(path, () => path).IsValidPath(PathValidationType.AnyOs);

Expand All @@ -44,10 +38,10 @@ public static string CleanFilePath(this string path)
// UNC
if (!info.FullName.Contains('/') && info.FullName.StartsWith(@"\\"))
{
return info.FullName.TrimEnd('/', '\\');
return info.FullName.TrimEnd('/', '\\', ' ');
}

return info.FullName.TrimEnd('/').Trim('\\');
return info.FullName.TrimEnd('/').Trim('\\', ' ');
}

public static bool PathNotEquals(this string firstPath, string secondPath, StringComparison? comparison = null)
Expand Down Expand Up @@ -161,23 +155,6 @@ public static bool IsPathValid(this string path, PathValidationType validationTy
return false;
}

if (path.Trim() != path)
{
return false;
}

var directoryInfo = new DirectoryInfo(path);

while (directoryInfo != null)
{
if (directoryInfo.Name.Trim() != directoryInfo.Name)
{
return false;
}

directoryInfo = directoryInfo.Parent;
}

if (validationType == PathValidationType.AnyOs)
{
return IsPathValidForWindows(path) || IsPathValidForNonWindows(path);
Expand Down Expand Up @@ -315,11 +292,6 @@ public static string ProcessNameToExe(this string processName)
return processName;
}

public static string CleanPath(this string path)
{
return Path.Join(path.Split(Path.DirectorySeparatorChar).Select(s => s.Trim()).ToArray());
}

public static string GetAppDataPath(this IAppFolderInfo appFolderInfo)
{
return appFolderInfo.AppDataFolder;
Expand Down
2 changes: 2 additions & 0 deletions src/Radarr.Api.V3/Movies/MovieController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public class MovieController : RestControllerWithSignalR<MovieResource, Movie>,
.When(s => s.Path.IsNullOrWhiteSpace());
PostValidator.RuleFor(s => s.Title).NotEmpty().When(s => s.TmdbId <= 0);
PostValidator.RuleFor(s => s.TmdbId).NotNull().NotEmpty().SetValidator(moviesExistsValidator);

PutValidator.RuleFor(s => s.Path).IsValidPath();
}

[HttpGet]
Expand Down

0 comments on commit 077b041

Please sign in to comment.