Files
Prowlarr-Prowlarr/src/NzbDrone.Core/Validation/Paths/PathValidator.cs
Mark McDowall d61275e6db New: Improve path validation when handling paths from different OSes
(cherry picked from commit 0321368cc392d7a0a488409bf6bd586ba45497af)
2023-05-06 16:30:20 +03:00

31 lines
855 B
C#

using FluentValidation;
using FluentValidation.Validators;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.Validation.Paths
{
public static class PathValidation
{
public static IRuleBuilderOptions<T, string> IsValidPath<T>(this IRuleBuilder<T, string> ruleBuilder)
{
return ruleBuilder.SetValidator(new PathValidator());
}
}
public class PathValidator : PropertyValidator
{
protected override string GetDefaultMessageTemplate() => "Invalid Path";
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null)
{
return false;
}
return context.PropertyValue.ToString().IsPathValid(PathValidationType.CurrentOs);
}
}
}