reason: '-[__NSCFString replaceOccurrencesOfString:withString:options:range:]: Range {0, 6} out of bounds; string length 2'

#58 · open · 2 comments

View on GitHub ↗

KittenYang

我遇到这个问题,i find the reason lies on RTLabel.m—— line 848~858: if (position!=NSNotFound) { if ([delimiter rangeOfString:@"<p"].location==0) { data = [data stringByReplacingOccurrencesOfString:delimiter withString:paragraphReplacement options:NSCaseInsensitiveSearch range:NSMakeRange(last_position, position+delimiter.length-last_position)]; } else { data = [data stringByReplacingOccurrencesOfString:delimiter withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(last_position, position+delimiter.length-last_position)]; } ``` data = [data stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"]; data = [data stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"]; } ``` How can i resolve it?THANKS!

Comments

Eloreden

i think that i have solved your problem on unsigned long position = [data rangeOfString:delimiter].location; // Here the problem because miss precision because position is declared like int if (position!=NSNotFound) { if ([delimiter rangeOfString:@"<p"].location==0) { data = [data stringByReplacingOccurrencesOfString:delimiter withString:paragraphReplacement options:NSCaseInsensitiveSearch range:NSMakeRange(last_position, position+delimiter.length-last_position)]; } else { data = [data stringByReplacingOccurrencesOfString:delimiter withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(last_position, position+delimiter.length-last_position)]; } ``` data = [data stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"]; data = [data stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"]; } ```

KittenYang

THX!Actually,I finally resolve it by changing RTLabel.m line 844- 858 like that: ``` int position = [data rangeOfString:delimiter options:NSCaseInsensitiveSearch range:NSMakeRange(last_position, [data length] - last_position)].location; if (position != NSNotFound && position >= last_position) { if ([delimiter rangeOfString:@"<p"].location==0) { data = [data stringByReplacingOccurrencesOfString:delimiter withString:paragraphReplacement options:NSCaseInsensitiveSearch range:NSMakeRange(position, delimiter.length)]; } else { data = [data stringByReplacingOccurrencesOfString:delimiter withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(position, delimiter.length)]; } data = [data stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"]; data = [data stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"]; } ``` :D