From 85fda9160444c86254c670d86bebc50e91bd3737 Mon Sep 17 00:00:00 2001 From: ta264 Date: Sun, 26 Jul 2020 21:20:50 +0100 Subject: [PATCH] Fix migration 178 to cope with leading/trailing slashes --- .../Migration/178_new_list_serverFixture.cs | 16 ++++++++++++---- .../Datastore/Migration/178_new_list_server.cs | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/NzbDrone.Core.Test/Datastore/Migration/178_new_list_serverFixture.cs b/src/NzbDrone.Core.Test/Datastore/Migration/178_new_list_serverFixture.cs index 011bb441e..68dc81570 100644 --- a/src/NzbDrone.Core.Test/Datastore/Migration/178_new_list_serverFixture.cs +++ b/src/NzbDrone.Core.Test/Datastore/Migration/178_new_list_serverFixture.cs @@ -35,12 +35,13 @@ namespace NzbDrone.Core.Test.Datastore.Migration } [TestCase("https://api.radarr.video/v2")] + [TestCase("https://api.radarr.video/v2/")] [TestCase("https://staging.api.radarr.video")] public void should_switch_some_radarr_to_imdb(string url) { var db = WithMigrationTestDb(c => { - var rows = Builder.CreateListOfSize(6) + var rows = Builder.CreateListOfSize(7) .All() .With(x => x.Implementation = typeof(RadarrListImport).Name) .With(x => x.ConfigContract = typeof(RadarrListSettings).Name) @@ -80,6 +81,12 @@ namespace NzbDrone.Core.Test.Datastore.Migration APIURL = url, Path = "/imdb/list?listId=ur002" }, _serializerSettings)) + .TheNext(1) + .With(x => x.Settings = JsonSerializer.Serialize(new new_list_server.RadarrListSettings177 + { + APIURL = url, + Path = "/imdb/list?listId=ur002/" + }, _serializerSettings)) .BuildListOfNew(); var i = 1; @@ -92,14 +99,15 @@ namespace NzbDrone.Core.Test.Datastore.Migration var items = db.Query("SELECT * FROM NetImport"); - items.Should().HaveCount(6); + items.Should().HaveCount(7); VerifyRow(items[0], typeof(IMDbListImport).Name, typeof(IMDbListSettings).Name, new IMDbListSettings { ListId = "top250" }); VerifyRow(items[1], typeof(IMDbListImport).Name, typeof(IMDbListSettings).Name, new IMDbListSettings { ListId = "popular" }); - VerifyRow(items[2], typeof(RadarrListImport).Name, typeof(RadarrListSettings).Name, new RadarrListSettings { Url = url + "/imdb/missing" }); + VerifyRow(items[2], typeof(RadarrListImport).Name, typeof(RadarrListSettings).Name, new RadarrListSettings { Url = url.TrimEnd('/') + "/imdb/missing" }); VerifyRow(items[3], typeof(IMDbListImport).Name, typeof(IMDbListSettings).Name, new IMDbListSettings { ListId = "ls001" }); - VerifyRow(items[4], typeof(RadarrListImport).Name, typeof(RadarrListSettings).Name, new RadarrListSettings { Url = url + "/imdb/list?listId=ls00ad" }); + VerifyRow(items[4], typeof(RadarrListImport).Name, typeof(RadarrListSettings).Name, new RadarrListSettings { Url = url.TrimEnd('/') + "/imdb/list?listId=ls00ad" }); VerifyRow(items[5], typeof(IMDbListImport).Name, typeof(IMDbListSettings).Name, new IMDbListSettings { ListId = "ur002" }); + VerifyRow(items[6], typeof(IMDbListImport).Name, typeof(IMDbListSettings).Name, new IMDbListSettings { ListId = "ur002" }); } public void should_switch_some_stevenlu_stevenlu2() diff --git a/src/NzbDrone.Core/Datastore/Migration/178_new_list_server.cs b/src/NzbDrone.Core/Datastore/Migration/178_new_list_server.cs index f35943b8f..4893f298d 100644 --- a/src/NzbDrone.Core/Datastore/Migration/178_new_list_server.cs +++ b/src/NzbDrone.Core/Datastore/Migration/178_new_list_server.cs @@ -14,7 +14,7 @@ namespace NzbDrone.Core.Datastore.Migration [Migration(178)] public class new_list_server : NzbDroneMigrationBase { - private static readonly Regex ImdbIdRegex = new Regex(@"^/?imdb/list\?listId=(?(ls|ur)\d+)$", + private static readonly Regex ImdbIdRegex = new Regex(@"^/*?imdb/list\?listId=(?(ls|ur)\d+)/*?$", RegexOptions.Compiled | RegexOptions.IgnoreCase); private readonly JsonSerializerOptions _serializerSettings; @@ -54,7 +54,7 @@ namespace NzbDrone.Core.Datastore.Migration var settings = JsonSerializer.Deserialize(row.Settings, _serializerSettings); object newSettings; - if (!radarrUrls.Contains(settings.APIURL)) + if (!radarrUrls.Contains(settings.APIURL.TrimEnd('/'))) { // Combine root and path in new settings newSettings = new RadarrListSettings178