Crash in NSRegularExpression stringByReplacingMatchesInString

Originator:roustem
Number:rdar://11635341 Date Originated:Jun 10, 2012
Status:Open Resolved:
Product:iOS SDK Product Version:5.1
Classification:Crash Reproducible:Always
 
Summary:

NSRegularExpression stringByReplacingMatchesInString:options:range: crashes in certain cases. 

Steps to Reproduce:

Sample code (please also see the attached project):
====
		NSString *matchPattern = @"(.*\\.)?(agile\\.ws|agilewebsolutions\\.com)$";
		NSString *template = @"$1agilebits.com";
	    
		NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:matchPattern options:0 error:NULL];
		
		NSString *noCrash = @"www.agile.ws";
		NSString *result1 = [regex stringByReplacingMatchesInString:noCrash options:0 range:NSMakeRange(0, [noCrash length]) withTemplate:template];
		
		if ([@"www.agilebits.com" isEqualToString:result1]) {
			NSLog(@"Works correctly for 'www.agile.ws'");
		}
		
		NSLog(@"Bug: will now throw exception when matching/replacing 'agile.ws'");
		NSString *crash = @"agile.ws";
		
		NSString *result2 = [regex stringByReplacingMatchesInString:crash options:0 range:NSMakeRange(0, [crash length]) withTemplate:template];
		
	    NSLog(@"This line won't be executed: %@", result2);
=======

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!