From 4d23e8a6bd1c5e8637089a7c5d49cdffbf7495d6 Mon Sep 17 00:00:00 2001 From: Lars-Erik Aabech Date: Mon, 10 Oct 2022 12:40:02 +0200 Subject: [PATCH] Ensure culture is always set in `LocalizeText` --- .../Controllers/BackOfficeController.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs index ae0b9c961f..70b0dc1ef7 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs @@ -255,7 +255,7 @@ public class BackOfficeController : UmbracoController [AllowAnonymous] public async Task>> LocalizedText(string? culture = null) { - CultureInfo? cultureInfo; + CultureInfo? cultureInfo = null; if (string.IsNullOrWhiteSpace(culture)) { // Force authentication to occur since this is not an authorized endpoint, we need this to get a user. @@ -264,9 +264,12 @@ public class BackOfficeController : UmbracoController // It's entirely likely for a user to have a different culture in the backoffice, than their system. IIdentity? user = authenticationResult.Principal?.Identity; - cultureInfo = authenticationResult.Succeeded && user is not null - ? user.GetCulture() - : CultureInfo.GetCultureInfo(_globalSettings.DefaultUILanguage); + if (authenticationResult.Succeeded && user is not null) + { + cultureInfo = user.GetCulture(); + } + + cultureInfo ??= CultureInfo.GetCultureInfo(_globalSettings.DefaultUILanguage); } else {