From 89af37462ebbe1da078a6f8b4e104475519eab97 Mon Sep 17 00:00:00 2001 From: Jellyfrog Date: Tue, 15 Sep 2026 11:13:49 -0400 Subject: Backport pull request #17844 from jellyfin/release-12.z Match parental ratings case-insensitively Original-merge: 7d0a33b76252d5d3fcb5d3b10cbedd7658623949 Merged-by: crobibero Backported-by: Cody Robibero --- .../Localization/LocalizationManager.cs | 29 ++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'Emby.Server.Implementations') diff --git a/Emby.Server.Implementations/Localization/LocalizationManager.cs b/Emby.Server.Implementations/Localization/LocalizationManager.cs index 0331ec39e5..65cb5379ea 100644 --- a/Emby.Server.Implementations/Localization/LocalizationManager.cs +++ b/Emby.Server.Implementations/Localization/LocalizationManager.cs @@ -139,7 +139,7 @@ namespace Emby.Server.Implementations.Localization var ratingSystem = await JsonSerializer.DeserializeAsync(stream, _jsonOptions).ConfigureAwait(false) ?? throw new InvalidOperationException($"Invalid resource path: '{CountriesPath}'"); - var dict = new Dictionary(); + var dict = new Dictionary(StringComparer.OrdinalIgnoreCase); if (ratingSystem.Ratings is not null) { foreach (var ratingEntry in ratingSystem.Ratings) @@ -374,12 +374,25 @@ namespace Emby.Server.Implementations.Localization { ArgumentException.ThrowIfNullOrEmpty(rating); + // Handle unrated content. This has to happen before the split below, + // because some of the unrated values contain a '/' themselves (e.g. "n/a"). + if (IsUnrated(rating)) + { + return null; + } + // Some providers may list multiple ratings separated by '/' (e.g. "SE:15 / SE:15+ / SE:Från 15 år"). // Try each one in order and use the first that resolves. var ratingValues = rating.Split('/', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); foreach (var ratingValue in ratingValues) { + // A single entry of such a list may be unrated while a later one still resolves + if (IsUnrated(ratingValue)) + { + continue; + } + var score = GetSingleRatingScore(ratingValue, countryCode); if (score is not null) { @@ -390,17 +403,19 @@ namespace Emby.Server.Implementations.Localization return null; } + /// + /// Checks whether a rating value marks the content as unrated. + /// + /// Rating value to check. + /// Returns true if the value is an unrated marker. + private static bool IsUnrated(ReadOnlySpan rating) + => _unratedValues.Contains(rating.Trim(), StringComparison.OrdinalIgnoreCase); + /// /// Resolves a single rating value to a score. /// private ParentalRatingScore? GetSingleRatingScore(string rating, string? countryCode) { - // Handle unrated content - if (_unratedValues.Contains(rating.AsSpan(), StringComparison.OrdinalIgnoreCase)) - { - return null; - } - // Convert ints directly // This may override some of the locale specific age ratings (but those always map to the same age) if (TryParseRatingAsScore(rating, out var ratingAge)) -- cgit v1.2.3