1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-25 20:22:37 +01:00

Fixed: Forbid empty spaces in Release Profile restrictions

This commit is contained in:
Bogdan 2024-08-31 06:25:32 +03:00 committed by GitHub
parent 44fab9a96c
commit 9136ee4ad9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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 @@ namespace Sonarr.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))

View File

@ -88,18 +88,18 @@ namespace Sonarr.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");