Skip to content

Commit

Permalink
Enforce UTF-8 encoding to fix the following issue (thoughtbot/griddle…
Browse files Browse the repository at this point in the history
  • Loading branch information
hughkolias authored and ccallebs committed Sep 18, 2018
1 parent ff7dce3 commit 90bd18e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/griddler/amazon_ses/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/griddler/amazon_ses_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 90bd18e

Please sign in to comment.