From f107ea5678a6a3153113fd6a87a0ef77c20ab216 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Tue, 3 Aug 2021 21:59:30 +0200 Subject: [PATCH] Simplified regex a bit. --- .../ReservedDeviceNameFixture.cs | 29 ++++++++++--------- .../Organizer/FileNameBuilder.cs | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/ReservedDeviceNameFixture.cs b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/ReservedDeviceNameFixture.cs index ca940bfc9..63e2dd4dd 100644 --- a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/ReservedDeviceNameFixture.cs +++ b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/ReservedDeviceNameFixture.cs @@ -50,37 +50,40 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests .Build(); _episodeFile = new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p), ReleaseGroup = "SonarrTest" }; - + Mocker.GetMock() .Setup(v => v.Get(Moq.It.IsAny())) .Returns(v => Quality.DefaultQualityDefinitions.First(c => c.Quality == v)); } - [Test] - public void should_replace_reserved_device_name_in_series_folder() + [TestCase("Con Game", "Con_Game")] + [TestCase("Com1 Sat", "Com1_Sat")] + public void should_replace_reserved_device_name_in_series_folder(string title, string expected) { - _series.Title = "Con Man"; + _series.Title = title; _namingConfig.SeriesFolderFormat = "{Series.Title}"; - Subject.GetSeriesFolder(_series).Should().Be("Con_Man"); + Subject.GetSeriesFolder(_series).Should().Be($"{expected}"); } - [Test] - public void should_replace_reserved_device_name_in_season_folder() + [TestCase("Con Game", "Con_Game")] + [TestCase("Com1 Sat", "Com1_Sat")] + public void should_replace_reserved_device_name_in_season_folder(string title, string expected) { - _series.Title = "Con Man"; + _series.Title = title; _namingConfig.SeasonFolderFormat = "{Series.Title} - Season {Season:00}"; - Subject.GetSeasonFolder(_series, 1).Should().Be("Con_Man - Season 01"); + Subject.GetSeasonFolder(_series, 1).Should().Be($"{expected} - Season 01"); } - [Test] - public void should_replace_reserved_device_name_in_file_name() + [TestCase("Con Game", "Con_Game")] + [TestCase("Com1 Sat", "Com1_Sat")] + public void should_replace_reserved_device_name_in_file_name(string title, string expected) { - _series.Title = "Con Man"; + _series.Title = title; _namingConfig.StandardEpisodeFormat = "{Series.Title} - S{Season:00}E{Episode:00}"; - Subject.BuildFileName(new List { _episode1 }, _series, _episodeFile).Should().Be("Con_Man - S15E06"); + Subject.BuildFileName(new List { _episode1 }, _series, _episodeFile).Should().Be($"{expected} - S15E06"); } } } diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 5028d95f8..2af9a08b3 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -80,7 +80,7 @@ namespace NzbDrone.Core.Organizer private static readonly Regex YearRegex = new Regex(@"\(\d{4}\)$", RegexOptions.Compiled | RegexOptions.IgnoreCase); - private static readonly Regex ReservedDeviceNamesRegex = new Regex(@"^(?:aux|com1|com2|com3|com4|com5|com6|com7|com8|com9|con|lpt1|lpt2|lpt3|lpt4|lpt5|lpt6|lpt7|lpt8|lpt9|nul|prn)\.", RegexOptions.Compiled | RegexOptions.IgnoreCase); + private static readonly Regex ReservedDeviceNamesRegex = new Regex(@"^(?:aux|com[1-9]|con|lpt[1-9]|nul|prn)\.", RegexOptions.Compiled | RegexOptions.IgnoreCase); public FileNameBuilder(INamingConfigService namingConfigService, IQualityDefinitionService qualityDefinitionService,