aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/incoming_message_spec.rb
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2015-05-12 13:51:48 +0100
committerLouise Crow <louise.crow@gmail.com>2015-05-15 16:14:47 +0100
commit73dcea8eba94472fb289fc85dd9e7106ed2974d1 (patch)
treeddec5f908be0dee5e73de0a5e23b8405a0d206e8 /spec/models/incoming_message_spec.rb
parentc283668016311ecef09286202832b846ddee9999 (diff)
Use mb_chars to prevent slicing multibyte chars under ruby 1.8
mb_chars provides a multibyte-aware wrapper for strings. It should have no effect on ruby 1.9.3 and above. Although ruby 1.8.7 wouldn't raise errors on a badly sliced multibyte string, on upgrading to ruby 1.9.3 and above, string operations such as gsub, match and join may produce ArgumentErrors with the message "invalid byte sequence in UTF-8". Additionally, a database with 'UTF-8' encoding may produce the error "PG::CharacterNotInRepertoire: ERROR: invalid byte sequence for encoding "UTF8""
Diffstat (limited to 'spec/models/incoming_message_spec.rb')
-rw-r--r--spec/models/incoming_message_spec.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index f6e524de3..ca9bbe39e 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -707,3 +707,15 @@ describe IncomingMessage, 'when getting the body of a message for html display'
end
end
+
+describe IncomingMessage, 'when getting clipped attachment text' do
+
+ it 'should clip to characters not bytes' do
+ incoming_message = FactoryGirl.build(:incoming_message)
+ # This character is 2 bytes so the string should get sliced unless
+ # we are handling multibyte chars correctly
+ multibyte_string = "å" * 500002
+ incoming_message.stub!(:_get_attachment_text_internal).and_return(multibyte_string)
+ incoming_message.get_attachment_text_clipped.length.should == 500002
+ end
+end \ No newline at end of file