mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-23 12:27:52 +08:00
Fix for nasty infinite loop when the resourcePath begins with a substitution param
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user