From 119addd75f21deaae5a7cb7b4eeeefb9a24a2aa1 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 4 Feb 2023 00:32:40 -0800 Subject: [PATCH] Fixed: Migrating case-sensitive Preferred Word REGEX to Custom Formats Closes #5399 --- .../171_add_custom_formatsFixture.cs | 64 +++++++++++++++++++ .../Migration/171_add_custom_formats.cs | 5 +- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core.Test/Datastore/Migration/171_add_custom_formatsFixture.cs b/src/NzbDrone.Core.Test/Datastore/Migration/171_add_custom_formatsFixture.cs index e9ee1a3be..6547f373d 100644 --- a/src/NzbDrone.Core.Test/Datastore/Migration/171_add_custom_formatsFixture.cs +++ b/src/NzbDrone.Core.Test/Datastore/Migration/171_add_custom_formatsFixture.cs @@ -482,6 +482,70 @@ namespace NzbDrone.Core.Test.Datastore.Migration customFormats.First().AnimeEpisodeFormat.Should().Be("{Series Title} - S{season:00}E{episode:00} - {Custom_Formats} {Quality Full}"); } + [Test] + public void should_migrate_case_sensitive_regex() + { + var db = WithMigrationTestDb(c => + { + c.Insert.IntoTable("ReleaseProfiles").Row(new + { + Name = "Profile", + Preferred = new[] + { + new + { + Key = "/somestring/", + Value = 2 + } + }.ToJson(), + Required = "[]", + Ignored = "[]", + Tags = "[]", + IncludePreferredWhenRenaming = true, + Enabled = true, + IndexerId = 0 + }); + }); + + var customFormats = db.Query("SELECT Id, Name, IncludeCustomFormatWhenRenaming, Specifications FROM CustomFormats"); + + customFormats.Should().HaveCount(1); + customFormats.First().Specifications.Should().HaveCount(1); + customFormats.First().Specifications.First().Body.Value.Should().Be("somestring"); + } + + [Test] + public void should_migrate_case_insensitive_regex() + { + var db = WithMigrationTestDb(c => + { + c.Insert.IntoTable("ReleaseProfiles").Row(new + { + Name = "Profile", + Preferred = new[] + { + new + { + Key = "/somestring/i", + Value = 2 + } + }.ToJson(), + Required = "[]", + Ignored = "[]", + Tags = "[]", + IncludePreferredWhenRenaming = true, + Enabled = true, + IndexerId = 0 + }); + }); + + var customFormats = db.Query("SELECT Id, Name, IncludeCustomFormatWhenRenaming, Specifications FROM CustomFormats"); + + customFormats.Should().HaveCount(1); + customFormats.First().Specifications.Should().HaveCount(1); + customFormats.First().Specifications.First().Body.Value.Should().Be("somestring"); + } + private class NamingConfig171 { public string StandardEpisodeFormat { get; set; } diff --git a/src/NzbDrone.Core/Datastore/Migration/171_add_custom_formats.cs b/src/NzbDrone.Core/Datastore/Migration/171_add_custom_formats.cs index 81fcd04b0..fa6ea1924 100644 --- a/src/NzbDrone.Core/Datastore/Migration/171_add_custom_formats.cs +++ b/src/NzbDrone.Core/Datastore/Migration/171_add_custom_formats.cs @@ -101,7 +101,10 @@ namespace NzbDrone.Core.Datastore.Migration foreach (var term in data) { - var regexTerm = term.Key.TrimStart('/').TrimEnd("/i"); + var regexTerm = term.Key + .TrimStart('/') + .TrimEnd('/') + .TrimEnd("/i"); // Validate Regex before creating a CF try