From ac9242308f85441077158d9b46a9f9c671e501ca Mon Sep 17 00:00:00 2001 From: baliasnyifeliks Date: Wed, 4 Feb 2026 20:58:48 +0200 Subject: [PATCH] fix(makhno): handle null season items when filtering by season number The code now properly handles cases where the requested season is not found in the voice seasons list by checking if the match has a valid Season before accessing its properties. This prevents potential null reference exceptions when generating season links. --- Makhno/Controller.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Makhno/Controller.cs b/Makhno/Controller.cs index 303754f..ce126f0 100644 --- a/Makhno/Controller.cs +++ b/Makhno/Controller.cs @@ -242,17 +242,19 @@ namespace Makhno if (seasonVoiceIndex.HasValue) { var voiceSeasonsForT = GetSeasonsWithNumbers(playerData.Voices[seasonVoiceIndex.Value]); - seasonItem = voiceSeasonsForT.FirstOrDefault(s => s.Number == seasonNumber); + var match = voiceSeasonsForT.FirstOrDefault(s => s.Number == seasonNumber); + seasonItem = match.Season != null ? match : ((Season Season, int Number)?)null; } else { - seasonItem = voiceSeasons + var match = voiceSeasons .SelectMany(v => v.Seasons) .FirstOrDefault(s => s.Number == seasonNumber); + seasonItem = match.Season != null ? match : ((Season Season, int Number)?)null; } string voiceParam = seasonVoiceIndex.HasValue ? $"&t={seasonVoiceIndex.Value}" : string.Empty; - string seasonName = seasonItem.Season?.Title ?? $"Сезон {seasonNumber}"; + string seasonName = seasonItem.HasValue ? seasonItem.Value.Season?.Title ?? $"Сезон {seasonNumber}" : $"Сезон {seasonNumber}"; string link = $"{host}/makhno?imdb_id={imdb_id}&title={HttpUtility.UrlEncode(title)}&original_title={HttpUtility.UrlEncode(original_title)}&year={year}&serial=1&season={seasonNumber}{voiceParam}"; season_tpl.Append(seasonName, link, seasonNumber.ToString()); }