aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/basic_encoding_spec.rb57
-rw-r--r--spec/lib/mail_handler/backends/mail_backend_spec.rb9
2 files changed, 65 insertions, 1 deletions
diff --git a/spec/lib/basic_encoding_spec.rb b/spec/lib/basic_encoding_spec.rb
index 1b3d9cd1c..d77465ad8 100644
--- a/spec/lib/basic_encoding_spec.rb
+++ b/spec/lib/basic_encoding_spec.rb
@@ -103,7 +103,7 @@ end
describe "convert_string_to_utf8_or_binary" do
- describe "when passed uniterpretable character data" do
+ describe "when passed uninterpretable character data" do
it "should return it as a binary string" do
@@ -155,3 +155,58 @@ describe "convert_string_to_utf8_or_binary" do
end
end
+
+describe "convert_string_to_utf8" do
+
+ describe "when passed uninterpretable character data" do
+
+ it "should return it as a utf8 string" do
+
+ converted = convert_string_to_utf8 random_string
+ converted.should == random_string
+
+ if String.method_defined?(:encode)
+ converted.encoding.to_s.should == 'UTF-8'
+ end
+
+ converted = convert_string_to_utf8 random_string,'UTF-8'
+ converted.should == random_string
+
+ if String.method_defined?(:encode)
+ converted.encoding.to_s.should == 'UTF-8'
+ end
+
+ end
+ end
+
+ describe "when passed unlabelled Windows 1252 data" do
+
+ it "should correctly convert it to UTF-8" do
+
+ converted = convert_string_to_utf8 windows_1252_string
+
+ converted.should == "DASH – DASH"
+
+ if String.method_defined?(:encode)
+ converted.encoding.to_s.should == 'UTF-8'
+ end
+ end
+
+ end
+
+ describe "when passed GB 18030 data" do
+
+ it "should correctly convert it to UTF-8 if unlabelled" do
+
+ converted = convert_string_to_utf8 gb_18030_spam_string
+
+ converted.should start_with("贵公司负责人")
+
+ if String.method_defined?(:encode)
+ converted.encoding.to_s.should == 'UTF-8'
+ end
+ end
+
+ end
+
+end \ No newline at end of file
diff --git a/spec/lib/mail_handler/backends/mail_backend_spec.rb b/spec/lib/mail_handler/backends/mail_backend_spec.rb
index dfd6dd1fe..044fbef4f 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