From d2b279a6be9cffdd95dcc57e7c0accc71d6a5ebb 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 (cherry picked from commit 4d8a4436810828494e99f0854cf6de3269668fe4) --- .../FileNameBuilderFixture.cs | 17 ++++++++++++++++- src/NzbDrone.Core/Organizer/FileNameBuilder.cs | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs index 102cd22d0..c376a6278 100644 --- a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs +++ b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs @@ -16,6 +16,7 @@ using NzbDrone.Core.Organizer; using NzbDrone.Core.Qualities; using NzbDrone.Core.Test.Framework; +using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests { @@ -292,7 +293,7 @@ public void use_path_when_sceneName_and_relative_path_are_null() { _namingConfig.RenameMovies = false; _movieFile.RelativePath = null; - _movieFile.Path = @"C:\Test\Unsorted\Movie - S01E01 - Test"; + _movieFile.Path = @"C:\Test\Unsorted\Movie - S01E01 - Test".AsOsAgnostic(); Subject.BuildFileName(_movie, _movieFile) .Should().Be(Path.GetFileNameWithoutExtension(_movieFile.Path)); @@ -309,6 +310,20 @@ public void use_file_name_when_sceneName_is_not_null() .Should().Be("30.Rock.S01E01.xvid-LOL"); } + [Test] + public void should_replace_illegal_characters_when_renaming_is_disabled() + { + _namingConfig.RenameMovies = false; + _namingConfig.ReplaceIllegalCharacters = true; + _namingConfig.ColonReplacementFormat = ColonReplacementFormat.Smart; + + _movieFile.SceneName = "30.Rock.S01E01.xvid:LOL"; + _movieFile.RelativePath = "30 Rock - S01E01 - Test"; + + Subject.BuildFileName(_movie, _movieFile) + .Should().Be("30.Rock.S01E01.xvid-LOL"); + } + [Test] public void should_should_replace_release_group() { diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 808ad335f..b5d4370c7 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -621,10 +621,10 @@ private string GetOriginalTitle(MovieFile movieFile, bool multipleTokens) { if (movieFile.SceneName.IsNullOrWhiteSpace()) { - return GetOriginalFileName(movieFile, multipleTokens); + return CleanFileName(GetOriginalFileName(movieFile, multipleTokens)); } - return movieFile.SceneName; + return CleanFileName(movieFile.SceneName); } private string GetOriginalFileName(MovieFile movieFile, bool multipleTokens)