From de7e805718d000a878a04ab4405b56bf54560e53 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 5 Mar 2019 18:08:34 -0800 Subject: [PATCH] Limit replacement of colons --- .../DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs | 2 +- .../FileNameBuilderTests/ReplaceCharacterFixure.cs | 1 + src/NzbDrone.Core/Organizer/FileNameBuilder.cs | 8 +++++++- .../Releases/TermMatchers/CaseInsensitiveTermMatcher.cs | 4 +++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs index 152f3abda..b3c1dc680 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs @@ -291,7 +291,7 @@ public void deleted_history_item_should_be_ignored() Subject.GetItems().Should().BeEmpty(); } - [TestCase("[ TOWN ]-[ http://www.town.ag ]-[ ANIME ]-[Usenet Provider >> http://www.ssl- <<] - [Commie] Aldnoah Zero 18 [234C8FC7]", "[ TOWN ]-[ http -++www.town.ag ]-[ ANIME ]-[Usenet Provider http -++www.ssl- ] - [Commie] Aldnoah Zero 18 [234C8FC7].nzb")] + [TestCase("[ TOWN ]-[ http://www.town.ag ]-[ ANIME ]-[Usenet Provider >> http://www.ssl- <<] - [Commie] Aldnoah Zero 18 [234C8FC7]", "[ TOWN ]-[ http-++www.town.ag ]-[ ANIME ]-[Usenet Provider http-++www.ssl- ] - [Commie] Aldnoah Zero 18 [234C8FC7].nzb")] public void Download_should_use_clean_title(string title, string filename) { GivenSuccessfulDownload(); diff --git a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/ReplaceCharacterFixure.cs b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/ReplaceCharacterFixure.cs index d0a727e31..ccf55f4ae 100644 --- a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/ReplaceCharacterFixure.cs +++ b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/ReplaceCharacterFixure.cs @@ -52,6 +52,7 @@ public void Setup() [TestCase("CSI: Crime Scene Investigation", "CSI - Crime Scene Investigation")] + [TestCase("Code:Breaker", "Code-Breaker")] [TestCase("Back Slash\\", "Back Slash+")] [TestCase("Forward Slash\\", "Forward Slash+")] [TestCase("Greater Than>", "Greater Than")] diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 6a34ce05e..c604f1b27 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -299,7 +299,13 @@ public static string CleanFileName(string name, bool replace = true) { string result = name; string[] badCharacters = { "\\", "/", "<", ">", "?", "*", ":", "|", "\"" }; - string[] goodCharacters = { "+", "+", "", "", "!", "-", " -", "", "" }; + string[] goodCharacters = { "+", "+", "", "", "!", "-", "-", "", "" }; + + // Replace a colon followed by a space with space dash space for a better appearance + if (replace) + { + result = result.Replace(": ", " - "); + } for (int i = 0; i < badCharacters.Length; i++) { diff --git a/src/NzbDrone.Core/Profiles/Releases/TermMatchers/CaseInsensitiveTermMatcher.cs b/src/NzbDrone.Core/Profiles/Releases/TermMatchers/CaseInsensitiveTermMatcher.cs index 305123420..21dad670e 100644 --- a/src/NzbDrone.Core/Profiles/Releases/TermMatchers/CaseInsensitiveTermMatcher.cs +++ b/src/NzbDrone.Core/Profiles/Releases/TermMatchers/CaseInsensitiveTermMatcher.cs @@ -2,10 +2,12 @@ { public sealed class CaseInsensitiveTermMatcher : ITermMatcher { + private readonly string _originalTerm; private readonly string _term; public CaseInsensitiveTermMatcher(string term) { + _originalTerm = term; _term = term.ToLowerInvariant(); } @@ -18,7 +20,7 @@ public string MatchingTerm(string value) { if (value.ToLowerInvariant().Contains(_term)) { - return _term; + return _originalTerm; } return null;