From 2e85a21576ecae4bb29fd59cb96d0d3e58a32fe5 Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 29 Sep 2022 20:14:18 -0500 Subject: [PATCH] Fixed: (GazelleGames) Serialization error on empty response Fixes #1137 --- .../Indexers/GazelleGames/recentfeed-empty.json | 4 ++++ .../GazelleGamesTests/GazelleGamesFixture.cs | 15 +++++++++++++++ .../Indexers/Definitions/GazelleGames.cs | 15 +++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/NzbDrone.Core.Test/Files/Indexers/GazelleGames/recentfeed-empty.json diff --git a/src/NzbDrone.Core.Test/Files/Indexers/GazelleGames/recentfeed-empty.json b/src/NzbDrone.Core.Test/Files/Indexers/GazelleGames/recentfeed-empty.json new file mode 100644 index 000000000..7230cc0e0 --- /dev/null +++ b/src/NzbDrone.Core.Test/Files/Indexers/GazelleGames/recentfeed-empty.json @@ -0,0 +1,4 @@ +{ + "status": "success", + "response": [] +} \ No newline at end of file diff --git a/src/NzbDrone.Core.Test/IndexerTests/GazelleGamesTests/GazelleGamesFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/GazelleGamesTests/GazelleGamesFixture.cs index dd3d7f7ae..e21852bf3 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/GazelleGamesTests/GazelleGamesFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/GazelleGamesTests/GazelleGamesFixture.cs @@ -12,6 +12,7 @@ using NzbDrone.Core.Indexers.Definitions; using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Test.Framework; +using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.IndexerTests.GazelleGamesTests { @@ -64,5 +65,19 @@ namespace NzbDrone.Core.Test.IndexerTests.GazelleGamesTests torrentInfo.DownloadVolumeFactor.Should().Be(1); torrentInfo.UploadVolumeFactor.Should().Be(1); } + + [Test] + public async Task should_not_error_if_empty_response() + { + var recentFeed = ReadAllText(@"Files/Indexers/GazelleGames/recentfeed-empty.json"); + + Mocker.GetMock() + .Setup(o => o.ExecuteProxiedAsync(It.Is(v => v.Method == HttpMethod.Get), Subject.Definition)) + .Returns((r, d) => Task.FromResult(new HttpResponse(r, new HttpHeader { { "Content-Type", "application/json" } }, new CookieCollection(), recentFeed))); + + var releases = (await Subject.Fetch(new BasicSearchCriteria { Categories = new int[] { 2000 } })).Releases; + + releases.Should().HaveCount(0); + } } } diff --git a/src/NzbDrone.Core/Indexers/Definitions/GazelleGames.cs b/src/NzbDrone.Core/Indexers/Definitions/GazelleGames.cs index d94a4addd..19afcbfd1 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/GazelleGames.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/GazelleGames.cs @@ -341,7 +341,18 @@ namespace NzbDrone.Core.Indexers.Definitions return torrentInfos; } - foreach (var result in jsonResponse.Resource.Response) + Dictionary response; + + try + { + response = ((JObject)jsonResponse.Resource.Response).ToObject>(); + } + catch + { + return torrentInfos; + } + + foreach (var result in response) { Dictionary torrents; @@ -455,7 +466,7 @@ namespace NzbDrone.Core.Indexers.Definitions public class GazelleGamesResponse { public string Status { get; set; } - public Dictionary Response { get; set; } + public object Response { get; set; } } public class GazelleGamesGroup