From 011fd57f7d066ec3e10c06eaa4a97f0e263900ab Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 5 Feb 2023 10:37:35 -0600 Subject: [PATCH] Fixed: Handle null IEnumerable field values in SchemaBuilder --- src/Prowlarr.Http/ClientSchema/SchemaBuilder.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Prowlarr.Http/ClientSchema/SchemaBuilder.cs b/src/Prowlarr.Http/ClientSchema/SchemaBuilder.cs index e955d35b1..37c8b2afb 100644 --- a/src/Prowlarr.Http/ClientSchema/SchemaBuilder.cs +++ b/src/Prowlarr.Http/ClientSchema/SchemaBuilder.cs @@ -226,7 +226,11 @@ namespace Prowlarr.Http.ClientSchema { return fieldValue => { - if (fieldValue is JsonElement e && e.ValueKind == JsonValueKind.Array) + if (fieldValue == null) + { + return Enumerable.Empty(); + } + else if (fieldValue is JsonElement e && e.ValueKind == JsonValueKind.Array) { return e.EnumerateArray().Select(s => s.GetInt32()); } @@ -240,13 +244,17 @@ namespace Prowlarr.Http.ClientSchema { return fieldValue => { - if (fieldValue is JsonElement e && e.ValueKind == JsonValueKind.Array) + if (fieldValue == null) + { + return Enumerable.Empty(); + } + else if (fieldValue is JsonElement e && e.ValueKind == JsonValueKind.Array) { return e.EnumerateArray().Select(s => s.GetString()); } else { - return fieldValue.ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(p => p.Trim()); + return fieldValue.ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(v => v.Trim()); } }; }