From 2d8b10d139deec3362f90d844d5ee0326324a6cf Mon Sep 17 00:00:00 2001 From: scossar Date: Fri, 4 Mar 2016 13:21:30 -0800 Subject: [PATCH] validate user locale --- app/mailers/user_notifications.rb | 2 +- spec/mailers/user_notifications_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb index 81ea701312f..d63dd23b92b 100644 --- a/app/mailers/user_notifications.rb +++ b/app/mailers/user_notifications.rb @@ -188,7 +188,7 @@ class UserNotifications < ActionMailer::Base protected def user_locale(user) - user.respond_to?(:locale) ? user.locale : nil + (user.locale.present? && I18n.available_locales.include?(user.locale.to_sym)) ? user.locale : nil end def email_post_markdown(post) diff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rb index 29466c08c02..076a601542f 100644 --- a/spec/mailers/user_notifications_spec.rb +++ b/spec/mailers/user_notifications_spec.rb @@ -429,5 +429,19 @@ describe UserNotifications do end end end + + context "user locale is not a valid locale" do + %w(signup signup_after_approval authorize_email forgot_password admin_login account_created).each do |mail_type| + include_examples "notification derived from template" do + SiteSetting.default_locale = "en" + let(:locale) { "invalid" } + let(:mail_type) { mail_type } + it "sets the locale" do + expects_build_with(has_entry(:locale, nil)) + end + end + end + end + end end