Sanitize locale input.
Closes CODEOCEAN-9E
This commit is contained in:
@ -71,7 +71,7 @@ class ApplicationController < ActionController::Base
|
|||||||
private :render_error
|
private :render_error
|
||||||
|
|
||||||
def switch_locale(&action)
|
def switch_locale(&action)
|
||||||
session[:locale] = params[:custom_locale] || params[:locale] || session[:locale]
|
session[:locale] = sanitize_locale(params[:custom_locale] || params[:locale] || session[:locale])
|
||||||
locale = session[:locale] || I18n.default_locale
|
locale = session[:locale] || I18n.default_locale
|
||||||
Sentry.set_extras(locale: locale)
|
Sentry.set_extras(locale: locale)
|
||||||
I18n.with_locale(locale, &action)
|
I18n.with_locale(locale, &action)
|
||||||
@ -96,4 +96,18 @@ class ApplicationController < ActionController::Base
|
|||||||
@embed_options
|
@embed_options
|
||||||
end
|
end
|
||||||
private :load_embed_options
|
private :load_embed_options
|
||||||
|
|
||||||
|
# Sanitize given locale.
|
||||||
|
#
|
||||||
|
# Return `nil` if the locale is blank or not available.
|
||||||
|
#
|
||||||
|
def sanitize_locale(locale)
|
||||||
|
return if locale.blank?
|
||||||
|
|
||||||
|
locale = locale.downcase.to_sym
|
||||||
|
return unless I18n.available_locales.include?(locale)
|
||||||
|
|
||||||
|
locale
|
||||||
|
end
|
||||||
|
private :sanitize_locale
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user