mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-26 22:46:53 -04:00
16ed68d5de
Fixes #7405
55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
using System.Text.RegularExpressions;
|
|
using FluentValidation;
|
|
using NzbDrone.Common.Extensions;
|
|
using NzbDrone.Core.Annotations;
|
|
using NzbDrone.Core.Validation;
|
|
|
|
namespace NzbDrone.Core.CustomFormats
|
|
{
|
|
public class RegexSpecificationBaseValidator : AbstractValidator<RegexSpecificationBase>
|
|
{
|
|
public RegexSpecificationBaseValidator()
|
|
{
|
|
RuleFor(c => c.Value).NotEmpty().WithMessage("Regex Pattern must not be empty");
|
|
}
|
|
}
|
|
|
|
public abstract class RegexSpecificationBase : CustomFormatSpecificationBase
|
|
{
|
|
private static readonly RegexSpecificationBaseValidator Validator = new RegexSpecificationBaseValidator();
|
|
|
|
protected Regex _regex;
|
|
protected string _raw;
|
|
|
|
[FieldDefinition(1, Label = "Regular Expression")]
|
|
public string Value
|
|
{
|
|
get => _raw;
|
|
set
|
|
{
|
|
_raw = value;
|
|
|
|
if (value.IsNotNullOrWhiteSpace())
|
|
{
|
|
_regex = new Regex(value, RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected bool MatchString(string compared)
|
|
{
|
|
if (compared == null || _regex == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return _regex.IsMatch(compared);
|
|
}
|
|
|
|
public override NzbDroneValidationResult Validate()
|
|
{
|
|
return new NzbDroneValidationResult(Validator.Validate(this));
|
|
}
|
|
}
|
|
}
|