Fixed: Forbid empty spaces in Release Profile restrictions

(cherry picked from commit 9136ee4ad934c10eef743e646f8b1c05eff2a2ff)
pull/10195/head
Bogdan 3 months ago
parent 4d589422e6
commit 8d189523c4

@ -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 });
};

@ -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 @@ namespace Radarr.Api.V3.Profiles.Release
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))

@ -88,18 +88,18 @@ namespace Radarr.Api.V3.Profiles.Release
{
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");

Loading…
Cancel
Save