From 88e793d76dc5d2631c61bb3a529c31e0caa6a0e1 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Tue, 6 Jun 2023 05:59:17 +0300 Subject: [PATCH] Fixed: (Cardigann) Allow empty inputs for login.method `form`/`post` --- .../Cardigann/CardigannRequestGenerator.cs | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannRequestGenerator.cs index 0076a02f7..814799752 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannRequestGenerator.cs @@ -203,10 +203,13 @@ namespace NzbDrone.Core.Indexers.Definitions.Cardigann { var pairs = new Dictionary(); - foreach (var input in login.Inputs) + if (login.Inputs != null && login.Inputs.Any()) { - var value = ApplyGoTemplateText(input.Value); - pairs.Add(input.Key, value); + foreach (var input in login.Inputs) + { + var value = ApplyGoTemplateText(input.Value); + pairs.Add(input.Key, value); + } } var loginUrl = ResolvePath(login.Path).ToString(); @@ -302,22 +305,25 @@ namespace NzbDrone.Core.Indexers.Definitions.Cardigann pairs[name] = value; } - foreach (var input in login.Inputs) + if (login.Inputs != null && login.Inputs.Any()) { - var value = ApplyGoTemplateText(input.Value); - var inputKey = input.Key; - if (login.Selectors) + foreach (var input in login.Inputs) { - var inputElement = landingResultDocument.QuerySelector(input.Key); - if (inputElement == null) + var value = ApplyGoTemplateText(input.Value); + var inputKey = input.Key; + if (login.Selectors) { - throw new CardigannConfigException(_definition, string.Format("Login failed: No input found using selector {0}", input.Key)); + var inputElement = landingResultDocument.QuerySelector(input.Key); + if (inputElement == null) + { + throw new CardigannConfigException(_definition, string.Format("Login failed: No input found using selector {0}", input.Key)); + } + + inputKey = inputElement.GetAttribute("name"); } - inputKey = inputElement.GetAttribute("name"); + pairs[inputKey] = value; } - - pairs[inputKey] = value; } // selector inputs