From f2012df3af066652bea0a88d0934e83da4907806 Mon Sep 17 00:00:00 2001 From: yury Date: Mon, 25 Jan 2016 22:25:12 +0300 Subject: [PATCH] Fix Out of bounds error Actually it is possible that truncated string is longer then original string. For example, original string: ``` hello this is very long message here and there ``` with maximumNumberOfLines=4, truncationAttributedString = ' ...' and additionalTruncationMessage = 'read more' will give ``` hello this is very long message here ... read more ``` So `[attributedString attribute:attributeName atIndex:characterIndex longestEffectiveRange:&range inRange:visibleRange]` will crash. --- AsyncDisplayKit/ASTextNode.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AsyncDisplayKit/ASTextNode.mm b/AsyncDisplayKit/ASTextNode.mm index f4dbea3800..bed2ce6305 100644 --- a/AsyncDisplayKit/ASTextNode.mm +++ b/AsyncDisplayKit/ASTextNode.mm @@ -479,6 +479,7 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ]; ASTextKitRenderer *renderer = [self _renderer]; NSRange visibleRange = renderer.visibleRanges[0]; NSAttributedString *attributedString = _attributedString; + NSRange clampedRange = NSIntersectionRange(visibleRange, NSMakeRange(0, attributedString.length)); // Check in a 9-point region around the actual touch point so we make sure // we get the best attribute for the touch. @@ -519,7 +520,7 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ]; for (NSString *attributeName in _linkAttributeNames) { NSRange range; - id value = [attributedString attribute:attributeName atIndex:characterIndex longestEffectiveRange:&range inRange:visibleRange]; + id value = [attributedString attribute:attributeName atIndex:characterIndex longestEffectiveRange:&range inRange:clampedRange]; NSString *name = attributeName; if (value == nil || name == nil) {