diff --git a/src/Lidarr.Api.V1/RemotePathMappings/RemotePathMappingController.cs b/src/Lidarr.Api.V1/RemotePathMappings/RemotePathMappingController.cs index 33edddff3..fae5b2388 100644 --- a/src/Lidarr.Api.V1/RemotePathMappings/RemotePathMappingController.cs +++ b/src/Lidarr.Api.V1/RemotePathMappings/RemotePathMappingController.cs @@ -4,6 +4,7 @@ using Lidarr.Http; using Lidarr.Http.REST; using Lidarr.Http.REST.Attributes; using Microsoft.AspNetCore.Mvc; +using NzbDrone.Common.Extensions; using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.Validation.Paths; @@ -21,11 +22,19 @@ namespace Lidarr.Api.V1.RemotePathMappings _remotePathMappingService = remotePathMappingService; SharedValidator.RuleFor(c => c.Host) - .NotEmpty(); + .NotEmpty(); // We cannot use IsValidPath here, because it's a remote path, possibly other OS. SharedValidator.RuleFor(c => c.RemotePath) - .NotEmpty(); + .NotEmpty(); + + SharedValidator.RuleFor(c => c.RemotePath) + .Must(remotePath => remotePath.IsNotNullOrWhiteSpace() && !remotePath.StartsWith(" ")) + .WithMessage("Remote Path '{PropertyValue}' must not start with a space"); + + SharedValidator.RuleFor(c => c.RemotePath) + .Must(remotePath => remotePath.IsNotNullOrWhiteSpace() && !remotePath.EndsWith(" ")) + .WithMessage("Remote Path '{PropertyValue}' must not end with a space"); SharedValidator.RuleFor(c => c.LocalPath) .Cascade(CascadeMode.Stop) diff --git a/src/NzbDrone.Core/RemotePathMappings/RemotePathMappingService.cs b/src/NzbDrone.Core/RemotePathMappings/RemotePathMappingService.cs index b757db3f3..9ee8a0ad0 100644 --- a/src/NzbDrone.Core/RemotePathMappings/RemotePathMappingService.cs +++ b/src/NzbDrone.Core/RemotePathMappings/RemotePathMappingService.cs @@ -96,6 +96,11 @@ namespace NzbDrone.Core.RemotePathMappings throw new ArgumentException("Invalid Host"); } + if (mapping.RemotePath.StartsWith(" ")) + { + throw new ArgumentException("Remote Path must not start with a space"); + } + var remotePath = new OsPath(mapping.RemotePath); var localPath = new OsPath(mapping.LocalPath);