From 75d38b737f196494f71f550b91d0dfc62cc8dfa9 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Fri, 20 Feb 2026 22:48:13 +0100 Subject: [PATCH] fix: validate locale cookie before setting I18n locale Fixes I18n::InvalidLocale error when cookie contains invalid/empty locale. Root cause: ApplicationController#set_locale was using the cookie value directly without validation, causing failures when users had an empty or invalid locale stored from previous sessions. --- app/controllers/application_controller.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b398d5420..e070d438c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -133,7 +133,14 @@ def has_access? def set_locale store_locale_to_cookie(params[:locale]) if locale - I18n.locale = cookies[:locale] || I18n.default_locale + I18n.locale = locale_value + end + + def locale_value + return I18n.default_locale unless cookies[:locale].present? + return I18n.default_locale unless I18n.available_locales.include?(cookies[:locale].to_sym) + + cookies[:locale] end def user_not_authorized