1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-19 17:32:38 +01:00

Fixed: Forbid empty spaces in Release Profile restrictions

(cherry picked from commit 9136ee4ad934c10eef743e646f8b1c05eff2a2ff)
This commit is contained in:
Bogdan 2024-08-31 06:25:32 +03:00
parent 4d589422e6
commit 8d189523c4
3 changed files with 27 additions and 7 deletions

View File

@ -49,7 +49,11 @@ class TextTagInputConnector extends Component {
const newTags = tag.name.startsWith('/') ? [tag.name] : split(tag.name);
newTags.forEach((newTag) => {
newValue.push(newTag.trim());
const newTagValue = newTag.trim();
if (newTagValue) {
newValue.push(newTagValue);
}
});
onChange({ name, value: newValue });
@ -80,7 +84,12 @@ class TextTagInputConnector extends Component {
const newValue = [...valueArray];
newValue.splice(tagToReplace.index, 1);
newValue.push(newTag.name.trim());
const newTagValue = newTag.name.trim();
if (newTagValue) {
newValue.push(newTagValue);
}
onChange({ name, value: newValue });
};

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using FluentValidation;
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Common.Extensions;
@ -23,9 +24,19 @@ public ReleaseProfileController(IReleaseProfileService profileService, IIndexerF
SharedValidator.RuleFor(d => d).Custom((restriction, context) =>
{
if (restriction.MapIgnored().Empty() && restriction.MapRequired().Empty())
if (restriction.MapRequired().Empty() && restriction.MapIgnored().Empty())
{
context.AddFailure("'Must contain' or 'Must not contain' is required");
context.AddFailure(nameof(ReleaseProfile.Required), "'Must contain' or 'Must not contain' is required");
}
if (restriction.MapRequired().Any(t => t.IsNullOrWhiteSpace()))
{
context.AddFailure(nameof(ReleaseProfile.Required), "'Must contain' should not contain whitespaces or an empty string");
}
if (restriction.MapIgnored().Any(t => t.IsNullOrWhiteSpace()))
{
context.AddFailure(nameof(ReleaseProfile.Ignored), "'Must not contain' should not contain whitespaces or an empty string");
}
if (restriction.Enabled && restriction.IndexerId != 0 && !_indexerFactory.Exists(restriction.IndexerId))

View File

@ -88,18 +88,18 @@ private static List<string> ParseArray(object resource, string title)
{
if (array.ValueKind == JsonValueKind.String)
{
return array.GetString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
return array.GetString().Split(new[] { ',' }, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries).ToList();
}
if (array.ValueKind == JsonValueKind.Array)
{
return JsonSerializer.Deserialize<List<string>>(array);
return array.Deserialize<List<string>>();
}
}
if (resource is string str)
{
return str.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
return str.Split(new[] { ',' }, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries).ToList();
}
throw new BadRequestException($"Invalid field {title}, should be string or string array");