From a96ff82e5313ea118ab2273b79ddc767be8f8447 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Mon, 13 Jul 2020 16:39:40 +0200 Subject: [PATCH] FIX: Set the lang/xml:lang html attrs in emails (#10218) In some rare cases emails are incorrectly sent out with lang placeholders in body (`xml:lang="%{html_lang}"`) --- app/helpers/email_helper.rb | 5 ++++- spec/mailers/user_notifications_spec.rb | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/helpers/email_helper.rb b/app/helpers/email_helper.rb index a1373329b8e..55b824ded30 100644 --- a/app/helpers/email_helper.rb +++ b/app/helpers/email_helper.rb @@ -26,7 +26,10 @@ module EmailHelper end def email_html_template - EmailStyle.new.html.sub('%{email_content}', capture { yield }).html_safe + EmailStyle.new.html + .sub('%{email_content}', capture { yield }) + .gsub('%{html_lang}', html_lang) + .html_safe end protected diff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rb index 38a7955e433..b438e095e49 100644 --- a/spec/mailers/user_notifications_spec.rb +++ b/spec/mailers/user_notifications_spec.rb @@ -236,6 +236,14 @@ describe UserNotifications do expect(html).to include(topic_url) expect(text).to include(topic_url) end + + it "applies lang/xml:lang html attributes" do + SiteSetting.default_locale = "pl_PL" + html = subject.html_part.to_s + + expect(html).to match(' lang="pl-PL"') + expect(html).to match(' xml:lang="pl-PL"') + end end end