aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/incoming_message.rb2
-rw-r--r--spec/models/incoming_message_spec.rb12
2 files changed, 13 insertions, 1 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index 658ee969a..4feee7637 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -654,7 +654,7 @@ class IncomingMessage < ActiveRecord::Base
# Save clipped version for snippets
if self.cached_attachment_text_clipped.nil?
- self.cached_attachment_text_clipped = text[0..MAX_ATTACHMENT_TEXT_CLIPPED]
+ self.cached_attachment_text_clipped = text.mb_chars[0..MAX_ATTACHMENT_TEXT_CLIPPED]
self.save!
end
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