From 90bd18e617317cbe6d68e841d57b85758d904b51 Mon Sep 17 00:00:00 2001 From: Hugh Kolias Date: Mon, 17 Sep 2018 21:07:55 -0400 Subject: [PATCH] Enforce UTF-8 encoding to fix the following issue (https://github.com/thoughtbot/griddler/issues/304) (#3) --- lib/griddler/amazon_ses/adapter.rb | 8 ++++++-- spec/griddler/amazon_ses_spec.rb | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/griddler/amazon_ses/adapter.rb b/lib/griddler/amazon_ses/adapter.rb index 794143a..755d734 100644 --- a/lib/griddler/amazon_ses/adapter.rb +++ b/lib/griddler/amazon_ses/adapter.rb @@ -84,11 +84,15 @@ def multipart? end def text_part - multipart? ? message.text_part.body.to_s : message.body.to_s + force_body_to_utf_8_string(multipart? ? message.text_part.body : message.body) end def html_part - multipart? ? message.html_part.body.to_s : nil + multipart? ? force_body_to_utf_8_string(message.html_part.body) : nil + end + + def force_body_to_utf_8_string(message_body) + message_body.to_s.force_encoding(Encoding::UTF_8) end def raw_headers diff --git a/spec/griddler/amazon_ses_spec.rb b/spec/griddler/amazon_ses_spec.rb index b57b139..2043f60 100644 --- a/spec/griddler/amazon_ses_spec.rb +++ b/spec/griddler/amazon_ses_spec.rb @@ -38,6 +38,10 @@ it 'parses out the text' do expect(Griddler::AmazonSES::Adapter.normalize_params(default_params)[:text]).to eq "Hi\n" end + + it 'should return the text body in UTF-8' do + expect(Griddler::AmazonSES::Adapter.normalize_params(default_params)[:text].encoding.to_s).to eq "UTF-8" + end end let(:default_params) {