From a118498f79abaac49fb6be508786f948f05ad502 Mon Sep 17 00:00:00 2001 From: crobibero Date: Mon, 13 May 2024 12:47:32 -0400 Subject: [PATCH] Backport pull request #11541 from jellyfin/release-10.9.z Fix migration with special Rating Original-merge: efba619acbe4849205874a464511ffcfd4aad2ba Merged-by: crobibero Backported-by: Joshua M. Boniface --- .../Localization/LocalizationManager.cs | 14 +++++++++++--- .../Localization/LocalizationManagerTests.cs | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Emby.Server.Implementations/Localization/LocalizationManager.cs b/Emby.Server.Implementations/Localization/LocalizationManager.cs index bae201c708..ac453a5b09 100644 --- a/Emby.Server.Implementations/Localization/LocalizationManager.cs +++ b/Emby.Server.Implementations/Localization/LocalizationManager.cs @@ -321,7 +321,11 @@ namespace Emby.Server.Implementations.Localization // Try splitting by : to handle "Germany: FSK-18" if (rating.Contains(':', StringComparison.OrdinalIgnoreCase)) { - return GetRatingLevel(rating.AsSpan().RightPart(':').ToString()); + var ratingLevelRightPart = rating.AsSpan().RightPart(':'); + if (ratingLevelRightPart.Length != 0) + { + return GetRatingLevel(ratingLevelRightPart.ToString()); + } } // Handle prefix country code to handle "DE-18" @@ -332,8 +336,12 @@ namespace Emby.Server.Implementations.Localization // Extract culture from country prefix var culture = FindLanguageInfo(ratingSpan.LeftPart('-').ToString()); - // Check rating system of culture - return GetRatingLevel(ratingSpan.RightPart('-').ToString(), culture?.TwoLetterISOLanguageName); + var ratingLevelRightPart = ratingSpan.RightPart('-'); + if (ratingLevelRightPart.Length != 0) + { + // Check rating system of culture + return GetRatingLevel(ratingLevelRightPart.ToString(), culture?.TwoLetterISOLanguageName); + } } return null; diff --git a/tests/Jellyfin.Server.Implementations.Tests/Localization/LocalizationManagerTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Localization/LocalizationManagerTests.cs index 0f7f5c1947..0a4a836cb3 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Localization/LocalizationManagerTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Localization/LocalizationManagerTests.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Emby.Server.Implementations.Localization; using MediaBrowser.Controller.Configuration; @@ -157,6 +158,20 @@ namespace Jellyfin.Server.Implementations.Tests.Localization Assert.Null(localizationManager.GetRatingLevel("n/a")); } + [Theory] + [InlineData("-NO RATING SHOWN-")] + [InlineData(":NO RATING SHOWN:")] + public async Task GetRatingLevel_Split_Success(string value) + { + var localizationManager = Setup(new ServerConfiguration() + { + UICulture = "en-US" + }); + await localizationManager.LoadAll(); + + Assert.Null(localizationManager.GetRatingLevel(value)); + } + [Theory] [InlineData("Default", "Default")] [InlineData("HeaderLiveTV", "Live TV")]