@@ -262,12 +262,13 @@ - (NSArray *)truncateProcessingResult:(NSArray *)processingResult
262262 continue ;
263263 }
264264
265+ NSUInteger clampedLength = MIN (range.length , cut - range.location );
265266 StylePair *clampedPair = [[StylePair alloc ] init ];
266- clampedPair.rangeValue = [NSValue
267- valueWithRange: NSMakeRange (range.location,
268- MIN (range.length, cut - range.location))];
267+ clampedPair.rangeValue =
268+ [NSValue valueWithRange: NSMakeRange (range.location, clampedLength)];
269269 clampedPair.styleValue = [self clampStyleValue: stylePair.styleValue
270- toLength: cut];
270+ toLength: cut
271+ clampedLength: clampedLength];
271272 [styles addObject: @[ styleInfo[0 ], clampedPair ]];
272273 }
273274
@@ -288,13 +289,26 @@ - (NSArray *)truncateProcessingResult:(NSArray *)processingResult
288289 return @[ [plainText substringToIndex: cut], styles, alignments ];
289290}
290291
291- // checkbox lists carry a { position: isChecked } dictionary which has to lose
292- // the entries pointing behind the truncated text
293- - (id )clampStyleValue:(id )styleValue toLength:(NSUInteger )length {
292+ - (id )clampStyleValue:(id )styleValue
293+ toLength:(NSUInteger )length
294+ clampedLength:(NSUInteger )clampedLength {
295+ // link's text value that is later inserted by addLink
296+ if ([styleValue isKindOfClass: [LinkData class ]]) {
297+ LinkData *linkData = (LinkData *)styleValue;
298+ if (linkData.text .length > clampedLength) {
299+ LinkData *clampedLinkData = [linkData copy ];
300+ clampedLinkData.text = [MaxLengthUtils truncate: linkData.text
301+ toCapacity: clampedLength];
302+ return clampedLinkData;
303+ }
304+ return styleValue;
305+ }
306+
294307 if (![styleValue isKindOfClass: [NSDictionary class ]]) {
295308 return styleValue;
296309 }
297310
311+ // checkbox list's { position: isChecked } dictionary
298312 NSDictionary *dictionary = (NSDictionary *)styleValue;
299313 NSMutableDictionary *clamped = [NSMutableDictionary new ];
300314 for (NSNumber *key in dictionary) {
0 commit comments