From 8f3492a026c9e6bbbdba542ac4e0ab077a9ef7b7 Mon Sep 17 00:00:00 2001 From: Heinrich Lee Yu <heinrich@gitlab.com> Date: Wed, 15 Jan 2025 14:37:44 +0800 Subject: [PATCH] Use UTF-8 encoding for email notifications Previously, we forced US-ASCII encoding to work around a bug in premailer 1.10.x. The bug is now fixed in 1.11.0 so we do not need this anymore. This also fixes how some mail servers handle HTML-encoded entities. Changelog: fixed --- config/initializers/premailer.rb | 1 - spec/mailers/notify_spec.rb | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/config/initializers/premailer.rb b/config/initializers/premailer.rb index ad80d80f0797..687f56eb884a 100644 --- a/config/initializers/premailer.rb +++ b/config/initializers/premailer.rb @@ -7,6 +7,5 @@ remove_comments: true, remove_ids: false, remove_scripts: false, - output_encoding: 'US-ASCII', strategies: ::Rails.env.production? ? [:asset_pipeline] : [:asset_pipeline, :network] ) diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index 9dcb0cdf103e..f845a3973512 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -89,16 +89,16 @@ end end - describe 'with HTML-encoded entities' do + describe 'with non-ASCII characters' do before do - described_class.test_email('test@test.com', 'Subject', 'Some body with —').deliver + described_class.test_email('test@test.com', 'Subject', 'Some body with 䏿–‡ —').deliver end subject { ActionMailer::Base.deliveries.last } - it 'retains 7bit encoding' do - expect(subject.body.ascii_only?).to eq(true) - expect(subject.body.encoding).to eq('7bit') + it 'removes HTML encoding and uses UTF-8 charset' do + expect(subject.charset).to eq('UTF-8') + expect(subject.body).to include('䏿–‡ —') end end -- GitLab