Prevent NullRef in naming when truncating a null Release Group

This commit is contained in:
Bogdan 2024-03-07 21:34:57 +02:00 committed by Mark McDowall
parent 61a7515041
commit 13e29bd257
1 changed files with 6 additions and 1 deletions

View File

@ -622,7 +622,7 @@ namespace NzbDrone.Core.Organizer
{ {
tokenHandlers["{Original Title}"] = m => GetOriginalTitle(episodeFile, useCurrentFilenameAsFallback); tokenHandlers["{Original Title}"] = m => GetOriginalTitle(episodeFile, useCurrentFilenameAsFallback);
tokenHandlers["{Original Filename}"] = m => GetOriginalFileName(episodeFile, useCurrentFilenameAsFallback); tokenHandlers["{Original Filename}"] = m => GetOriginalFileName(episodeFile, useCurrentFilenameAsFallback);
tokenHandlers["{Release Group}"] = m => Truncate(episodeFile.ReleaseGroup, m.CustomFormat) ?? m.DefaultValue("Sonarr"); tokenHandlers["{Release Group}"] = m => episodeFile.ReleaseGroup.IsNullOrWhiteSpace() ? m.DefaultValue("Sonarr") : Truncate(episodeFile.ReleaseGroup, m.CustomFormat);
} }
private void AddQualityTokens(Dictionary<string, Func<TokenMatch, string>> tokenHandlers, Series series, EpisodeFile episodeFile) private void AddQualityTokens(Dictionary<string, Func<TokenMatch, string>> tokenHandlers, Series series, EpisodeFile episodeFile)
@ -1168,6 +1168,11 @@ namespace NzbDrone.Core.Organizer
private string Truncate(string input, string formatter) private string Truncate(string input, string formatter)
{ {
if (input.IsNullOrWhiteSpace())
{
return string.Empty;
}
var maxLength = GetMaxLengthFromFormatter(formatter); var maxLength = GetMaxLengthFromFormatter(formatter);
if (maxLength == 0 || input.Length <= Math.Abs(maxLength)) if (maxLength == 0 || input.Length <= Math.Abs(maxLength))