Skip to content

Commit 75d38b7

Browse files
committed
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.
1 parent cd866c3 commit 75d38b7

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

app/controllers/application_controller.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,14 @@ def has_access?
133133

134134
def set_locale
135135
store_locale_to_cookie(params[:locale]) if locale
136-
I18n.locale = cookies[:locale] || I18n.default_locale
136+
I18n.locale = locale_value
137+
end
138+
139+
def locale_value
140+
return I18n.default_locale unless cookies[:locale].present?
141+
return I18n.default_locale unless I18n.available_locales.include?(cookies[:locale].to_sym)
142+
143+
cookies[:locale]
137144
end
138145

139146
def user_not_authorized

0 commit comments

Comments
 (0)