Skip to content

Commit

Permalink
Fix crash on adding attachments, due to replacing range out of bounds.
Browse files Browse the repository at this point in the history
  • Loading branch information
kishikawakatsumi committed Mar 8, 2014
1 parent c27708f commit 8a06c57
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Lib/SETextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,23 @@ - (void)setTextAttachmentAttributes
{
NSString *replacementString = OBJECT_REPLACEMENT_CHARACTER;

for (SETextAttachment *attachment in self.attachments) {
NSArray *attachments = [self.attachments.allObjects sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
SETextAttachment *attachment1 = obj1;
SETextAttachment *attachment2 = obj2;
NSRange range1 = attachment1.range;
NSRange range2 = attachment2.range;
NSUInteger maxRange1 = NSMaxRange(range1);
NSUInteger maxRange2 = NSMaxRange(range2);
if (maxRange1 < maxRange2) {
return NSOrderedDescending;
} else if (maxRange1 > maxRange2) {
return NSOrderedAscending;
} else {
return NSOrderedSame;
}
}];

for (SETextAttachment *attachment in attachments) {
NSMutableAttributedString *editingAttributedText = self.editingAttributedText;
if (!attachment.replacedString) {
if (attachment.range.length > 0) {
Expand Down

0 comments on commit 8a06c57

Please sign in to comment.