Fix for nasty infinite loop when the resourcePath begins with a substitution param

This commit is contained in:
Blake Watters
2010-10-21 11:42:47 -04:00
parent 32fe2d3e24
commit deef2a63ce
4 changed files with 19 additions and 6 deletions

View File

@@ -78,18 +78,15 @@
NSMutableDictionary* substitutions = [NSMutableDictionary dictionary];
NSScanner* scanner = [NSScanner scannerWithString:resourcePath];
BOOL startsWithParentheses = [[resourcePath substringToIndex:1] isEqualToString:@"("];
while ([scanner isAtEnd] == NO) {
NSString* keyPath = nil;
BOOL scannedToOpenParan = [scanner scanUpToString:@"(" intoString:nil];
if (scannedToOpenParan || [resourcePath characterAtIndex:0] == [@"(" characterAtIndex:0]) {
if (startsWithParentheses || [scanner scanUpToString:@"(" intoString:nil]) {
// Advance beyond the opening parentheses
if (scannedToOpenParan && NO == [scanner isAtEnd]) {
if (NO == [scanner isAtEnd]) {
[scanner setScanLocation:[scanner scanLocation] + 1];
}
if ([scanner scanUpToString:@")" intoString:&keyPath]) {
if (!scannedToOpenParan) {
keyPath = [keyPath substringFromIndex:1];
}
NSString* searchString = [NSString stringWithFormat:@"(%@)", keyPath];
NSString* propertyStringValue = [NSString stringWithFormat:@"%@", [object valueForKeyPath:keyPath]];
[substitutions setObject:propertyStringValue forKey:searchString];

View File

@@ -169,6 +169,7 @@ static const NSString* kRKModelMapperMappingFormatParserKey = @"RKMappingFormatP
NSDictionary* elements = [dictionary objectForKey:elementName];
[self updateModel:model fromElements:elements];
} else {
// TODO: Can't we just check if this thing implements RKObjectMappable and try to map it if so???
[NSException raise:@"Unable to map from requested dictionary"
format:@"There was no mappable element found for objects of type %@", class];
}