From 8d189523c4c46cc997a9496b55f2d67fcbd916e0 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sat, 31 Aug 2024 06:25:32 +0300 Subject: [PATCH] Fixed: Forbid empty spaces in Release Profile restrictions (cherry picked from commit 9136ee4ad934c10eef743e646f8b1c05eff2a2ff) --- .../src/Components/Form/TextTagInputConnector.js | 13 +++++++++++-- .../Profiles/Release/ReleaseProfileController.cs | 15 +++++++++++++-- .../Profiles/Release/ReleaseProfileResource.cs | 6 +++--- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/frontend/src/Components/Form/TextTagInputConnector.js b/frontend/src/Components/Form/TextTagInputConnector.js index 17677a51e..be5abb16e 100644 --- a/frontend/src/Components/Form/TextTagInputConnector.js +++ b/frontend/src/Components/Form/TextTagInputConnector.js @@ -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 }); }; diff --git a/src/Radarr.Api.V3/Profiles/Release/ReleaseProfileController.cs b/src/Radarr.Api.V3/Profiles/Release/ReleaseProfileController.cs index 6a54fe620..72aa81201 100644 --- a/src/Radarr.Api.V3/Profiles/Release/ReleaseProfileController.cs +++ b/src/Radarr.Api.V3/Profiles/Release/ReleaseProfileController.cs @@ -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)) diff --git a/src/Radarr.Api.V3/Profiles/Release/ReleaseProfileResource.cs b/src/Radarr.Api.V3/Profiles/Release/ReleaseProfileResource.cs index beb10323f..54b49ba73 100644 --- a/src/Radarr.Api.V3/Profiles/Release/ReleaseProfileResource.cs +++ b/src/Radarr.Api.V3/Profiles/Release/ReleaseProfileResource.cs @@ -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>(array); + return array.Deserialize>(); } } 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");