aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2015-05-14 17:11:24 +0100
committerLouise Crow <louise.crow@gmail.com>2015-05-15 16:25:15 +0100
commitf198ca6944cb5ad5b81efbe42233837b8b773fbb (patch)
treecf2076727ab19219d052cd86dc1ab09af55d373e /spec/lib
parent203eea18feeaec3dc9a3e8e8af3b83de085b53ac (diff)
Force attachment filenames to utf-8 before trying to save them
In a database with encoding SQL-ASCII, an invalid utf-8 filename can be saved but will cause an "invalid byte sequence in UTF-8" when the filename is prepared for display. In a database with a UTF-8 encoding, saving the string will cause an error like "ActiveRecord::StatementInvalid (PG::Error: ERROR: invalid byte sequence for encoding "UTF8""
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/mail_handler/backends/mail_backend_spec.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/spec/lib/mail_handler/backends/mail_backend_spec.rb b/spec/lib/mail_handler/backends/mail_backend_spec.rb
index 588033faf..895160670 100644
--- a/spec/lib/mail_handler/backends/mail_backend_spec.rb
+++ b/spec/lib/mail_handler/backends/mail_backend_spec.rb
@@ -37,6 +37,15 @@ describe MailHandler::Backends::MailBackend do
get_part_file_name(part).should be_nil
end
+ it 'turns an invalid UTF-8 name into a valid one' do
+ mail = get_fixture_mail('non-utf8-filename.email')
+ part = mail.attachments.first
+ filename = get_part_file_name(part)
+ if filename.respond_to?(:valid_encoding)
+ filename.valid_encoding?.should == true
+ end
+ end
+
end
describe :get_part_body do