From 4d8a4436810828494e99f0854cf6de3269668fe4 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 5 Sep 2024 20:46:10 -0700 Subject: [PATCH] Fixed: Replace illegal characters even when renaming is disabled Closes #7183 --- .../FileNameBuilderFixture.cs | 16 +++++++++++++++- src/NzbDrone.Core/Organizer/FileNameBuilder.cs | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs index 3b0cdb0af..710dfe30a 100644 --- a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs +++ b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs @@ -274,7 +274,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests { _namingConfig.RenameEpisodes = false; _episodeFile.RelativePath = null; - _episodeFile.Path = @"C:\Test\Unsorted\Series - S01E01 - Test"; + _episodeFile.Path = @"C:\Test\Unsorted\Series - S01E01 - Test".AsOsAgnostic(); Subject.BuildFileName(new List { _episode1 }, _series, _episodeFile) .Should().Be(Path.GetFileNameWithoutExtension(_episodeFile.Path)); @@ -291,6 +291,20 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests .Should().Be("30.Rock.S01E01.xvid-LOL"); } + [Test] + public void should_replace_illegal_characters_when_renaming_is_disabled() + { + _namingConfig.RenameEpisodes = false; + _namingConfig.ReplaceIllegalCharacters = true; + _namingConfig.ColonReplacementFormat = ColonReplacementFormat.Smart; + + _episodeFile.SceneName = "30.Rock.S01E01.xvid:LOL"; + _episodeFile.RelativePath = "30 Rock - S01E01 - Test"; + + Subject.BuildFileName(new List { _episode1 }, _series, _episodeFile) + .Should().Be("30.Rock.S01E01.xvid-LOL"); + } + [Test] public void should_use_airDate_if_series_isDaily_and_not_a_special() { diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 952b8f593..2ee358bef 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -1116,10 +1116,10 @@ namespace NzbDrone.Core.Organizer { if (episodeFile.SceneName.IsNullOrWhiteSpace()) { - return GetOriginalFileName(episodeFile, useCurrentFilenameAsFallback); + return CleanFileName(GetOriginalFileName(episodeFile, useCurrentFilenameAsFallback)); } - return episodeFile.SceneName; + return CleanFileName(episodeFile.SceneName); } private string GetOriginalFileName(EpisodeFile episodeFile, bool useCurrentFilenameAsFallback)