Skip to content

Commit f7ea200

Browse files
authored
Merge pull request #2497 from mroderick/fix/invalid-locale-cookie-error
fix: validate locale cookie before setting I18n locale
2 parents 5fe4a0e + 75d38b7 commit f7ea200

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
@@ -138,7 +138,14 @@ def admin_namespace?
138138

139139
def set_locale
140140
store_locale_to_cookie(params[:locale]) if locale
141-
I18n.locale = cookies[:locale] || I18n.default_locale
141+
I18n.locale = locale_value
142+
end
143+
144+
def locale_value
145+
return I18n.default_locale unless cookies[:locale].present?
146+
return I18n.default_locale unless I18n.available_locales.include?(cookies[:locale].to_sym)
147+
148+
cookies[:locale]
142149
end
143150

144151
def user_not_authorized

0 commit comments

Comments
 (0)